mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 10:15:35 +01:00
test: use mockery generated artifact Manager in tests
Closes #14284 Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
parent
66b8a8f8dd
commit
fec9f59a43
@ -206,7 +206,7 @@ var (
|
||||
|
||||
type abstractorTestSuite struct {
|
||||
suite.Suite
|
||||
argMgr *tart.FakeManager
|
||||
argMgr *tart.Manager
|
||||
blobMgr *tblob.Manager
|
||||
regCli *registry.FakeClient
|
||||
abstractor *abstractor
|
||||
@ -215,7 +215,7 @@ type abstractorTestSuite struct {
|
||||
|
||||
func (a *abstractorTestSuite) SetupTest() {
|
||||
a.regCli = ®istry.FakeClient{}
|
||||
a.argMgr = &tart.FakeManager{}
|
||||
a.argMgr = &tart.Manager{}
|
||||
a.blobMgr = &tblob.Manager{}
|
||||
a.abstractor = &abstractor{
|
||||
artMgr: a.argMgr,
|
||||
@ -272,7 +272,7 @@ func (a *abstractorTestSuite) TestAbstractMetadataOfIndex() {
|
||||
manifest, _, err := distribution.UnmarshalManifest(v1.MediaTypeImageIndex, []byte(index))
|
||||
a.Require().Nil(err)
|
||||
a.regCli.On("PullManifest").Return(manifest, "", nil)
|
||||
a.argMgr.On("GetByDigest").Return(&artifact.Artifact{
|
||||
a.argMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 2,
|
||||
Size: 10,
|
||||
}, nil)
|
||||
|
@ -16,7 +16,6 @@ package artifact
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/immutable"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -38,6 +37,7 @@ import (
|
||||
arttesting "github.com/goharbor/harbor/src/testing/pkg/artifact"
|
||||
artrashtesting "github.com/goharbor/harbor/src/testing/pkg/artifactrash"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/blob"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/immutable"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/label"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/registry"
|
||||
repotesting "github.com/goharbor/harbor/src/testing/pkg/repository"
|
||||
@ -61,7 +61,7 @@ type controllerTestSuite struct {
|
||||
suite.Suite
|
||||
ctl *controller
|
||||
repoMgr *repotesting.Manager
|
||||
artMgr *arttesting.FakeManager
|
||||
artMgr *arttesting.Manager
|
||||
artrashMgr *artrashtesting.FakeManager
|
||||
blobMgr *blob.Manager
|
||||
tagCtl *tagtesting.FakeController
|
||||
@ -73,7 +73,7 @@ type controllerTestSuite struct {
|
||||
|
||||
func (c *controllerTestSuite) SetupTest() {
|
||||
c.repoMgr = &repotesting.Manager{}
|
||||
c.artMgr = &arttesting.FakeManager{}
|
||||
c.artMgr = &arttesting.Manager{}
|
||||
c.artrashMgr = &artrashtesting.FakeManager{}
|
||||
c.blobMgr = &blob.Manager{}
|
||||
c.tagCtl = &tagtesting.FakeController{}
|
||||
@ -195,7 +195,7 @@ func (c *controllerTestSuite) TestEnsureArtifact() {
|
||||
digest := "sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180"
|
||||
|
||||
// the artifact already exists
|
||||
c.artMgr.On("GetByDigest").Return(&artifact.Artifact{
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
created, art, err := c.ctl.ensureArtifact(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest)
|
||||
@ -210,8 +210,8 @@ func (c *controllerTestSuite) TestEnsureArtifact() {
|
||||
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
|
||||
ProjectID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("GetByDigest").Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Create").Return(1, nil)
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), nil)
|
||||
c.abstractor.On("AbstractMetadata").Return(nil)
|
||||
created, art, err = c.ctl.ensureArtifact(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest)
|
||||
c.Require().Nil(err)
|
||||
@ -226,8 +226,8 @@ func (c *controllerTestSuite) TestEnsure() {
|
||||
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
|
||||
ProjectID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("GetByDigest").Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Create").Return(1, nil)
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), nil)
|
||||
c.abstractor.On("AbstractMetadata").Return(nil)
|
||||
c.tagCtl.On("Ensure").Return(nil)
|
||||
_, id, err := c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest, "latest")
|
||||
@ -240,7 +240,7 @@ func (c *controllerTestSuite) TestEnsure() {
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) TestCount() {
|
||||
c.artMgr.On("Count").Return(1, nil)
|
||||
c.artMgr.On("Count", mock.Anything, mock.Anything).Return(int64(1), nil)
|
||||
total, err := c.ctl.Count(nil, nil)
|
||||
c.Require().Nil(err)
|
||||
c.Equal(int64(1), total)
|
||||
@ -251,7 +251,7 @@ func (c *controllerTestSuite) TestList() {
|
||||
option := &Option{
|
||||
WithTag: true,
|
||||
}
|
||||
c.artMgr.On("List").Return([]*artifact.Artifact{
|
||||
c.artMgr.On("List", mock.Anything, mock.Anything).Return([]*artifact.Artifact{
|
||||
{
|
||||
ID: 1,
|
||||
RepositoryID: 1,
|
||||
@ -282,7 +282,7 @@ func (c *controllerTestSuite) TestList() {
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) TestGet() {
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
@ -298,7 +298,7 @@ func (c *controllerTestSuite) TestGetByDigest() {
|
||||
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("GetByDigest").Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
art, err := c.ctl.getByDigest(nil, "library/hello-world",
|
||||
"sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180", nil)
|
||||
c.Require().NotNil(err)
|
||||
@ -311,7 +311,7 @@ func (c *controllerTestSuite) TestGetByDigest() {
|
||||
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("GetByDigest").Return(&artifact.Artifact{
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
@ -350,7 +350,7 @@ func (c *controllerTestSuite) TestGetByTag() {
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil)
|
||||
@ -365,7 +365,7 @@ func (c *controllerTestSuite) TestGetByReference() {
|
||||
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("GetByDigest").Return(&artifact.Artifact{
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
@ -393,7 +393,7 @@ func (c *controllerTestSuite) TestGetByReference() {
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil)
|
||||
@ -405,7 +405,7 @@ func (c *controllerTestSuite) TestGetByReference() {
|
||||
|
||||
func (c *controllerTestSuite) TestDeleteDeeply() {
|
||||
// root artifact and doesn't exist
|
||||
c.artMgr.On("Get").Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
err := c.ctl.deleteDeeply(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, true)
|
||||
c.Require().NotNil(err)
|
||||
c.Assert().True(errors.IsErr(err, errors.NotFoundCode))
|
||||
@ -414,7 +414,7 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
|
||||
c.SetupTest()
|
||||
|
||||
// child artifact and doesn't exist
|
||||
c.artMgr.On("Get").Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
err = c.ctl.deleteDeeply(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, false)
|
||||
c.Require().Nil(err)
|
||||
|
||||
@ -422,8 +422,8 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
|
||||
c.SetupTest()
|
||||
|
||||
// child artifact and contains tags
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{ID: 1}, nil)
|
||||
c.artMgr.On("Delete").Return(nil)
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{ID: 1}, nil)
|
||||
c.artMgr.On("Delete", mock.Anything, mock.Anything).Return(nil)
|
||||
c.tagCtl.On("List").Return([]*tag.Tag{
|
||||
{
|
||||
Tag: model_tag.Tag{
|
||||
@ -440,10 +440,10 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
|
||||
c.SetupTest()
|
||||
|
||||
// root artifact is referenced by other artifacts
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{ID: 1}, nil)
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{ID: 1}, nil)
|
||||
c.tagCtl.On("List").Return(nil, nil)
|
||||
c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil)
|
||||
c.artMgr.On("ListReferences").Return([]*artifact.Reference{
|
||||
c.artMgr.On("ListReferences", mock.Anything, mock.Anything).Return([]*artifact.Reference{
|
||||
{
|
||||
ID: 1,
|
||||
},
|
||||
@ -455,10 +455,10 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
|
||||
c.SetupTest()
|
||||
|
||||
// child artifact contains no tag but referenced by other artifacts
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{ID: 1}, nil)
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{ID: 1}, nil)
|
||||
c.tagCtl.On("List").Return(nil, nil)
|
||||
c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil)
|
||||
c.artMgr.On("ListReferences").Return([]*artifact.Reference{
|
||||
c.artMgr.On("ListReferences", mock.Anything, mock.Anything).Return([]*artifact.Reference{
|
||||
{
|
||||
ID: 1,
|
||||
},
|
||||
@ -468,7 +468,7 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) TestCopy() {
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{
|
||||
ID: 1,
|
||||
Digest: "sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180",
|
||||
}, nil)
|
||||
@ -476,8 +476,8 @@ func (c *controllerTestSuite) TestCopy() {
|
||||
RepositoryID: 1,
|
||||
Name: "library/hello-world",
|
||||
}, nil)
|
||||
c.artMgr.On("Count").Return(0, nil)
|
||||
c.artMgr.On("GetByDigest").Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Count", mock.Anything, mock.Anything).Return(int64(0), nil)
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
c.tagCtl.On("List").Return([]*tag.Tag{
|
||||
{
|
||||
Tag: model_tag.Tag{
|
||||
@ -492,7 +492,7 @@ func (c *controllerTestSuite) TestCopy() {
|
||||
Name: "library/hello-world",
|
||||
}, nil)
|
||||
c.abstractor.On("AbstractMetadata").Return(nil)
|
||||
c.artMgr.On("Create").Return(1, nil)
|
||||
c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), nil)
|
||||
c.regCli.On("Copy").Return(nil)
|
||||
c.tagCtl.On("Ensure").Return(nil)
|
||||
_, err := c.ctl.Copy(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", "latest", "library/hello-world2")
|
||||
@ -508,7 +508,7 @@ func (c *controllerTestSuite) TestUpdatePullTime() {
|
||||
},
|
||||
}, nil)
|
||||
c.tagCtl.On("Update").Return(nil)
|
||||
c.artMgr.On("Update").Return(nil)
|
||||
c.artMgr.On("Update", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
err := c.ctl.UpdatePullTime(nil, 1, 1, time.Now())
|
||||
c.Require().Nil(err)
|
||||
c.artMgr.AssertExpectations(c.T())
|
||||
@ -524,7 +524,7 @@ func (c *controllerTestSuite) TestUpdatePullTime() {
|
||||
ArtifactID: 2,
|
||||
},
|
||||
}, nil)
|
||||
c.artMgr.On("Update").Return(nil)
|
||||
c.artMgr.On("Update", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
err = c.ctl.UpdatePullTime(nil, 1, 1, time.Now())
|
||||
c.Require().NotNil(err)
|
||||
c.tagCtl.AssertExpectations(c.T())
|
||||
@ -532,7 +532,7 @@ func (c *controllerTestSuite) TestUpdatePullTime() {
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) TestGetAddition() {
|
||||
c.artMgr.On("Get").Return(&artifact.Artifact{}, nil)
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&artifact.Artifact{}, nil)
|
||||
_, err := c.ctl.GetAddition(nil, 1, "addition")
|
||||
c.Require().NotNil(err)
|
||||
}
|
||||
@ -550,7 +550,7 @@ func (c *controllerTestSuite) TestRemoveFrom() {
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) TestWalk() {
|
||||
c.artMgr.On("List").Return([]*artifact.Artifact{
|
||||
c.artMgr.On("List", mock.Anything, mock.Anything).Return([]*artifact.Artifact{
|
||||
{Digest: "d1", ManifestMediaType: v1.MediaTypeImageManifest},
|
||||
{Digest: "d2", ManifestMediaType: v1.MediaTypeImageManifest},
|
||||
}, nil)
|
||||
|
@ -36,12 +36,12 @@ var (
|
||||
type controllerTestSuite struct {
|
||||
suite.Suite
|
||||
controller Controller
|
||||
argMgr *artifact_testing.FakeManager
|
||||
argMgr *artifact_testing.Manager
|
||||
regCli *registry.FakeClient
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) SetupTest() {
|
||||
c.argMgr = &artifact_testing.FakeManager{}
|
||||
c.argMgr = &artifact_testing.Manager{}
|
||||
c.regCli = ®istry.FakeClient{}
|
||||
c.controller = &controller{
|
||||
artMgr: c.argMgr,
|
||||
|
@ -15,12 +15,12 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
proModels "github.com/goharbor/harbor/src/pkg/project/models"
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/controller/artifact"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
proModels "github.com/goharbor/harbor/src/pkg/project/models"
|
||||
"github.com/goharbor/harbor/src/pkg/repository/model"
|
||||
artifacttesting "github.com/goharbor/harbor/src/testing/controller/artifact"
|
||||
ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
|
||||
@ -36,14 +36,14 @@ type controllerTestSuite struct {
|
||||
ctl *controller
|
||||
proMgr *project.Manager
|
||||
repoMgr *repository.Manager
|
||||
argMgr *arttesting.FakeManager
|
||||
argMgr *arttesting.Manager
|
||||
artCtl *artifacttesting.Controller
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) SetupTest() {
|
||||
c.proMgr = &project.Manager{}
|
||||
c.repoMgr = &repository.Manager{}
|
||||
c.argMgr = &arttesting.FakeManager{}
|
||||
c.argMgr = &arttesting.Manager{}
|
||||
c.artCtl = &artifacttesting.Controller{}
|
||||
c.ctl = &controller{
|
||||
proMgr: c.proMgr,
|
||||
@ -125,7 +125,7 @@ func (c *controllerTestSuite) TestGetByName() {
|
||||
func (c *controllerTestSuite) TestDelete() {
|
||||
art := &artifact.Artifact{}
|
||||
art.ID = 1
|
||||
c.argMgr.On("ListReferences").Return(nil, nil)
|
||||
mock.OnAnything(c.argMgr, "ListReferences").Return(nil, nil)
|
||||
mock.OnAnything(c.artCtl, "List").Return([]*artifact.Artifact{art}, nil)
|
||||
mock.OnAnything(c.artCtl, "Delete").Return(nil)
|
||||
c.repoMgr.On("Delete", mock.Anything, mock.Anything).Return(nil)
|
||||
|
@ -15,6 +15,9 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/common"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
@ -27,23 +30,22 @@ import (
|
||||
"github.com/goharbor/harbor/src/testing/pkg/immutable"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/repository"
|
||||
tagtesting "github.com/goharbor/harbor/src/testing/pkg/tag"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type controllerTestSuite struct {
|
||||
suite.Suite
|
||||
ctl *controller
|
||||
repoMgr *repository.Manager
|
||||
artMgr *artifact.FakeManager
|
||||
artMgr *artifact.Manager
|
||||
tagMgr *tagtesting.FakeManager
|
||||
immutableMtr *immutable.FakeMatcher
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) SetupTest() {
|
||||
c.repoMgr = &repository.Manager{}
|
||||
c.artMgr = &artifact.FakeManager{}
|
||||
c.artMgr = &artifact.Manager{}
|
||||
c.tagMgr = &tagtesting.FakeManager{}
|
||||
c.immutableMtr = &immutable.FakeMatcher{}
|
||||
c.ctl = &controller{
|
||||
@ -68,7 +70,7 @@ func (c *controllerTestSuite) TestEnsureTag() {
|
||||
Name: "latest",
|
||||
},
|
||||
}, nil)
|
||||
c.artMgr.On("Get").Return(&pkg_artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.immutableMtr.On("Match").Return(false, nil)
|
||||
@ -89,7 +91,7 @@ func (c *controllerTestSuite) TestEnsureTag() {
|
||||
},
|
||||
}, nil)
|
||||
c.tagMgr.On("Update").Return(nil)
|
||||
c.artMgr.On("Get").Return(&pkg_artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.immutableMtr.On("Match").Return(false, nil)
|
||||
@ -103,7 +105,7 @@ func (c *controllerTestSuite) TestEnsureTag() {
|
||||
// the tag doesn't exist under the repository, create it
|
||||
c.tagMgr.On("List").Return([]*tag.Tag{}, nil)
|
||||
c.tagMgr.On("Create").Return(1, nil)
|
||||
c.artMgr.On("Get").Return(&pkg_artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.immutableMtr.On("Match").Return(false, nil)
|
||||
@ -151,7 +153,7 @@ func (c *controllerTestSuite) TestDelete() {
|
||||
RepositoryID: 1,
|
||||
Name: "test",
|
||||
}, nil)
|
||||
c.artMgr.On("Get").Return(&pkg_artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.immutableMtr.On("Match").Return(false, nil)
|
||||
@ -165,7 +167,7 @@ func (c *controllerTestSuite) TestDeleteImmutable() {
|
||||
RepositoryID: 1,
|
||||
Name: "test",
|
||||
}, nil)
|
||||
c.artMgr.On("Get").Return(&pkg_artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.immutableMtr.On("Match").Return(true, nil)
|
||||
@ -191,7 +193,7 @@ func (c *controllerTestSuite) TestDeleteTags() {
|
||||
c.tagMgr.On("Get").Return(&tag.Tag{
|
||||
RepositoryID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("Get").Return(&pkg_artifact.Artifact{
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
|
||||
ID: 1,
|
||||
}, nil)
|
||||
c.immutableMtr.On("Match").Return(false, nil)
|
||||
@ -221,7 +223,7 @@ func (c *controllerTestSuite) TestAssembleTag() {
|
||||
WithImmutableStatus: true,
|
||||
}
|
||||
|
||||
c.artMgr.On("Get").Return(art, nil)
|
||||
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(art, nil)
|
||||
c.immutableMtr.On("Match").Return(true, nil)
|
||||
tag := c.ctl.assembleTag(nil, tg, option)
|
||||
c.Require().NotNil(tag)
|
||||
|
@ -1,97 +0,0 @@
|
||||
// Copyright Project Harbor Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package artifact
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/artifact"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// FakeManager is a fake artifact manager that implement src/pkg/artifact.Manager interface
|
||||
type FakeManager struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// Count ...
|
||||
func (f *FakeManager) Count(ctx context.Context, query *q.Query) (int64, error) {
|
||||
args := f.Called()
|
||||
return int64(args.Int(0)), args.Error(1)
|
||||
}
|
||||
|
||||
// List ...
|
||||
func (f *FakeManager) List(ctx context.Context, query *q.Query) ([]*artifact.Artifact, error) {
|
||||
args := f.Called()
|
||||
var artifacts []*artifact.Artifact
|
||||
if args.Get(0) != nil {
|
||||
artifacts = args.Get(0).([]*artifact.Artifact)
|
||||
}
|
||||
return artifacts, args.Error(1)
|
||||
}
|
||||
|
||||
// Get ...
|
||||
func (f *FakeManager) Get(ctx context.Context, id int64) (*artifact.Artifact, error) {
|
||||
args := f.Called()
|
||||
var art *artifact.Artifact
|
||||
if args.Get(0) != nil {
|
||||
art = args.Get(0).(*artifact.Artifact)
|
||||
}
|
||||
return art, args.Error(1)
|
||||
}
|
||||
|
||||
// GetByDigest ...
|
||||
func (f *FakeManager) GetByDigest(ctx context.Context, repository, digest string) (*artifact.Artifact, error) {
|
||||
args := f.Called()
|
||||
var art *artifact.Artifact
|
||||
if args.Get(0) != nil {
|
||||
art = args.Get(0).(*artifact.Artifact)
|
||||
}
|
||||
return art, args.Error(1)
|
||||
}
|
||||
|
||||
// Create ...
|
||||
func (f *FakeManager) Create(ctx context.Context, artifact *artifact.Artifact) (int64, error) {
|
||||
args := f.Called()
|
||||
return int64(args.Int(0)), args.Error(1)
|
||||
}
|
||||
|
||||
// Delete ...
|
||||
func (f *FakeManager) Delete(ctx context.Context, id int64) error {
|
||||
args := f.Called()
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
// UpdatePullTime ...
|
||||
func (f *FakeManager) Update(ctx context.Context, artifact *artifact.Artifact, props ...string) error {
|
||||
args := f.Called()
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
// ListReferences ...
|
||||
func (f *FakeManager) ListReferences(ctx context.Context, query *q.Query) ([]*artifact.Reference, error) {
|
||||
args := f.Called()
|
||||
var references []*artifact.Reference
|
||||
if args.Get(0) != nil {
|
||||
references = args.Get(0).([]*artifact.Reference)
|
||||
}
|
||||
return references, args.Error(1)
|
||||
}
|
||||
|
||||
// DeleteReference ...
|
||||
func (f *FakeManager) DeleteReference(ctx context.Context, id int64) error {
|
||||
args := f.Called()
|
||||
return args.Error(0)
|
||||
}
|
Loading…
Reference in New Issue
Block a user