Skip to content

Commit

Permalink
Fix missed error mapping on service side when version doesn't exist (#…
Browse files Browse the repository at this point in the history
…197)

Related #150

Signed-off-by: Igor Shishkin <me@teran.dev>
  • Loading branch information
teran authored Sep 1, 2024
1 parent c0a66a2 commit 432fc8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 9 additions & 9 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ type Publisher interface {
}

type service struct {
mdRepo metadata.Repository
blobRepo blob.Repository
versionsPageSize uint64
objectsPageSize uint64
mdRepo metadata.Repository
blobRepo blob.Repository
versionsPageSize uint64
objectsPageSize uint64
containersPageSize uint64
}

Expand All @@ -68,10 +68,10 @@ func NewPublisher(mdRepo metadata.Repository, blobRepo blob.Repository, versions

func newSvc(mdRepo metadata.Repository, blobRepo blob.Repository, versionsPerPage, objectsPerPage, containersPerPage uint64) *service {
return &service{
mdRepo: mdRepo,
blobRepo: blobRepo,
versionsPageSize: versionsPerPage,
objectsPageSize: objectsPerPage,
mdRepo: mdRepo,
blobRepo: blobRepo,
versionsPageSize: versionsPerPage,
objectsPageSize: objectsPerPage,
containersPageSize: containersPerPage,
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func (s *service) ListObjectsByPage(ctx context.Context, namespace, container, v
limit := s.objectsPageSize
totalObjects, objects, err := s.mdRepo.ListObjects(ctx, namespace, container, versionID, offset, limit)
if err != nil {
return 0, nil, err
return 0, nil, mapMetadataErrors(err)
}

totalPages := (totalObjects / s.objectsPageSize)
Expand Down
9 changes: 8 additions & 1 deletion service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func (s *serviceTestSuite) TestListContainers() {
s.Require().Equal("test error", err.Error())
}


func (s *serviceTestSuite) TestListContainersByPage() {
s.mdRepoMock.On("ListContainersByPage", defaultNamespace, uint64(300), uint64(50)).Return(uint64(200), []models.Container{
{Name: "container1"},
Expand Down Expand Up @@ -293,6 +292,14 @@ func (s *serviceTestSuite) TestListObjectsByLatestVersion() {
s.Require().Equal([]string{"obj1", "obj2"}, objects)
}

func (s *serviceTestSuite) TestListObjectsErrNotFound() {
s.mdRepoMock.On("ListObjects", defaultNamespace, "container1", "versionID", uint64(0), uint64(50)).Return(uint64(100), []string{"obj1", "obj2"}, metadata.ErrNotFound).Once()

_, _, err := s.svc.ListObjectsByPage(s.ctx, defaultNamespace, "container1", "versionID", 1)
s.Require().Error(err)
s.Require().Equal(ErrNotFound, err)
}

func (s *serviceTestSuite) TestGetObjectURLWithLatestVersion() {
s.mdRepoMock.On("GetLatestPublishedVersionByContainer", defaultNamespace, "container12").Return("versionID", nil).Once()
s.mdRepoMock.On("GetBlobKeyByObject", defaultNamespace, "container12", "versionID", "key").Return("deadbeef", nil).Once()
Expand Down

0 comments on commit 432fc8e

Please sign in to comment.