Skip to content

Commit

Permalink
✅ Update dao test (#344)
Browse files Browse the repository at this point in the history
* ✨ Update blob cacher

* ✅ Update dao test
  • Loading branch information
tosone authored Mar 19, 2024
1 parent 2fa292c commit 4de7c8c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 35 deletions.
14 changes: 5 additions & 9 deletions pkg/dal/dao/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ func TestAuditServiceFactory(t *testing.T) {
func TestAuditService(t *testing.T) {
viper.SetDefault("log.level", "debug")
logger.SetLevel("debug")
err := tests.Initialize(t)
assert.NoError(t, err)
err = tests.DB.Init()
assert.NoError(t, err)
assert.NoError(t, tests.Initialize(t))
assert.NoError(t, tests.DB.Init())
defer func() {
conn, err := dal.DB.DB()
assert.NoError(t, err)
err = conn.Close()
assert.NoError(t, err)
err = tests.DB.DeInit()
assert.NoError(t, err)
assert.NoError(t, conn.Close())
assert.NoError(t, tests.DB.DeInit())
}()

ctx := log.Logger.WithContext(context.Background())
Expand All @@ -67,7 +63,7 @@ func TestAuditService(t *testing.T) {
assert.NotNil(t, namespaceService)

namespaceObj1 := &models.Namespace{Name: "test"}
err = namespaceService.Create(ctx, namespaceObj1)
err := namespaceService.Create(ctx, namespaceObj1)
assert.NoError(t, err)

userServiceFactory := dao.NewUserServiceFactory()
Expand Down
13 changes: 5 additions & 8 deletions pkg/dal/dao/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,21 @@ func TestBlobServiceFactory(t *testing.T) {
func TestBlobService(t *testing.T) {
viper.SetDefault("log.level", "debug")
logger.SetLevel("debug")
err := tests.Initialize(t)
assert.NoError(t, err)
err = tests.DB.Init()
assert.NoError(t, err)
assert.NoError(t, tests.Initialize(t))
assert.NoError(t, tests.DB.Init())
defer func() {
conn, err := dal.DB.DB()
assert.NoError(t, err)
err = conn.Close()
assert.NoError(t, err)
assert.NoError(t, conn.Close())
assert.NoError(t, tests.DB.DeInit())
}()

ctx := log.Logger.WithContext(context.Background())

f := dao.NewBlobServiceFactory()
err = query.Q.Transaction(func(tx *query.Query) error {
err := query.Q.Transaction(func(tx *query.Query) error {
blobService := f.New(tx)
err = blobService.Create(ctx, &models.Blob{
err := blobService.Create(ctx, &models.Blob{
Digest: "sha256:123",
Size: 123,
ContentType: "test",
Expand Down
10 changes: 2 additions & 8 deletions pkg/dal/dao/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,6 @@ func (s *namespaceService) UpdateByID(ctx context.Context, id int64, updates map
if len(updates) == 0 {
return nil
}
matched, err := s.tx.Namespace.WithContext(ctx).Where(s.tx.Namespace.ID.Eq(id)).Updates(updates)
if err != nil {
return err
}
if matched.RowsAffected == 0 {
return gorm.ErrRecordNotFound
}
return nil
_, err := s.tx.Namespace.WithContext(ctx).Where(s.tx.Namespace.ID.Eq(id)).Updates(updates)
return err
}
3 changes: 0 additions & 3 deletions pkg/dal/dao/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ func TestNamespaceService(t *testing.T) {
err = namespaceService.UpdateByID(ctx, namespaceObj.ID, map[string]interface{}{query.Namespace.Description.ColumnName().String(): "test"})
assert.NoError(t, err)

err = namespaceService.UpdateByID(ctx, 10, map[string]interface{}{query.Namespace.Description.ColumnName().String(): "test"})
assert.ErrorIs(t, err, gorm.ErrRecordNotFound)

err = namespaceService.DeleteByID(ctx, namespaceObj.ID)
assert.NoError(t, err)

Expand Down
6 changes: 2 additions & 4 deletions pkg/dal/dao/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ func TestRepositoryService(t *testing.T) {
defer func() {
conn, err := dal.DB.DB()
assert.NoError(t, err)
err = conn.Close()
assert.NoError(t, err)
err = tests.DB.DeInit()
assert.NoError(t, err)
assert.NoError(t, conn.Close())
assert.NoError(t, tests.DB.DeInit())
}()

ctx := log.Logger.WithContext(context.Background())
Expand Down
1 change: 1 addition & 0 deletions pkg/types/enums/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type CacherType string
// redis,
// kafka,
// database,
// inmemory,
// )
type WorkQueueType string

Expand Down
9 changes: 6 additions & 3 deletions pkg/types/enums/enums_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4de7c8c

Please sign in to comment.