Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Jul 3, 2024
1 parent a9398b7 commit 9d73b73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share.

blobs, err := s.getBlobs(ctx, namespace, header)
if err != nil && !errors.Is(err, ErrBlobNotFound) {
log.Debugf("getting blobs for namespace(%s): %v", namespace.String(), err)
log.Errorf("getting blobs for namespaceID(%s): %v", namespace.ID().String(), err)
resultErr[i] = err
}
if len(blobs) > 0 {
Expand Down
25 changes: 18 additions & 7 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestBlobService_Get(t *testing.T) {
expectedResult: func(i interface{}, err error) {
blobs, ok := i.([]*Blob)
require.True(t, ok)
assert.Empty(t, blobs)
assert.Nil(t, blobs)
assert.Nil(t, err)
},
},
Expand All @@ -334,18 +334,29 @@ func TestBlobService_Get(t *testing.T) {
name: "internal error",
doFn: func() (interface{}, error) {
ctrl := gomock.NewController(t)
shareService := service.shareGetter
shareGetterMock := shareMock.NewMockModule(ctrl)
service.shareGetter = shareGetterMock
shareGetterMock.EXPECT().
GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil, errors.New("internal error"))
return service.GetAll(ctx, 1, []share.Namespace{blobs0[0].Namespace()})
DoAndReturn(
func(ctx context.Context, h *header.ExtendedHeader, ns share.Namespace) (share.NamespacedShares, error) {
if ns.Equals(blobs0[0].Namespace()) {
return nil, errors.New("internal error")
}
return shareService.GetSharesByNamespace(ctx, h, ns)
}).AnyTimes()

service.shareGetter = shareGetterMock
return service.GetAll(ctx, 1, []share.Namespace{blobs0[0].Namespace(), blobs1[0].Namespace()})
},
expectedResult: func(res interface{}, err error) {
blobs, ok := res.([]*Blob)
require.True(t, ok)
assert.Empty(t, blobs)
require.Error(t, err)
assert.True(t, ok)
assert.Error(t, err)
assert.Contains(t, err.Error(), "internal error")
assert.Equal(t, blobs[0].Namespace(), blobs1[0].Namespace())
assert.NotEmpty(t, blobs)
assert.Len(t, blobs, len(blobs1))
},
},
}
Expand Down

0 comments on commit 9d73b73

Please sign in to comment.