refactor: unify the mock file generation (#20765)

1. Mock remote interface for distribution manifest by mockery package
feature.
2. Refactor hand-generated mock files to automated management
   generation.
3. Clean useless mocks.

Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
Chlins Zhang 2024-08-05 19:11:05 +08:00 committed by GitHub
parent 295e075568
commit 5deedf4c7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 926 additions and 654 deletions

View File

@ -9,6 +9,17 @@ packages:
Controller: Controller:
config: config:
dir: testing/controller/artifact dir: testing/controller/artifact
github.com/goharbor/harbor/src/controller/artifact/processor:
interfaces:
Processor:
config:
dir: testing/pkg/processor
github.com/goharbor/harbor/src/controller/artifact/annotation:
interfaces:
Parser:
config:
dir: testing/pkg/parser
outpkg: parser
github.com/goharbor/harbor/src/controller/blob: github.com/goharbor/harbor/src/controller/blob:
interfaces: interfaces:
Controller: Controller:
@ -188,6 +199,11 @@ packages:
Manager: Manager:
config: config:
dir: testing/pkg/artifact dir: testing/pkg/artifact
github.com/goharbor/harbor/src/pkg/artifactrash:
interfaces:
Manager:
config:
dir: testing/pkg/artifactrash
github.com/goharbor/harbor/src/pkg/blob: github.com/goharbor/harbor/src/pkg/blob:
interfaces: interfaces:
Manager: Manager:
@ -218,6 +234,11 @@ packages:
Handler: Handler:
config: config:
dir: testing/pkg/scan dir: testing/pkg/scan
github.com/goharbor/harbor/src/pkg/scan/postprocessors:
interfaces:
NativeScanReportConverter:
config:
dir: testing/pkg/scan/postprocessors
github.com/goharbor/harbor/src/pkg/scan/report: github.com/goharbor/harbor/src/pkg/scan/report:
interfaces: interfaces:
Manager: Manager:
@ -238,7 +259,7 @@ packages:
dir: pkg/scheduler dir: pkg/scheduler
outpkg: scheduler outpkg: scheduler
mockname: mockDAO mockname: mockDAO
filename: mock_dao_test.go filename: mock_dao_test.go
inpackage: True inpackage: True
Scheduler: Scheduler:
config: config:
@ -342,6 +363,14 @@ packages:
DAO: DAO:
config: config:
dir: testing/pkg/immutable/dao dir: testing/pkg/immutable/dao
github.com/goharbor/harbor/src/pkg/immutable/match:
interfaces:
ImmutableTagMatcher:
config:
dir: testing/pkg/immutable
filename: matcher.go
outpkg: immutable
mockname: FakeMatcher
github.com/goharbor/harbor/src/pkg/ldap: github.com/goharbor/harbor/src/pkg/ldap:
interfaces: interfaces:
Manager: Manager:
@ -505,20 +534,36 @@ packages:
Manager: Manager:
config: config:
dir: testing/pkg/securityhub dir: testing/pkg/securityhub
github.com/goharbor/harbor/src/pkg/tag:
interfaces:
Manager:
config:
dir: testing/pkg/tag
github.com/goharbor/harbor/src/pkg/p2p/preheat/policy:
interfaces:
Manager:
config:
dir: testing/pkg/p2p/preheat/policy
github.com/goharbor/harbor/src/pkg/p2p/preheat/instance:
interfaces:
Manager:
config:
dir: testing/pkg/p2p/preheat/instance
github.com/goharbor/harbor/src/pkg/chart:
interfaces:
Operator:
config:
dir: testing/pkg/chart
# registryctl related mocks
github.com/goharbor/harbor/src/registryctl/client:
interfaces:
Client:
config:
dir: testing/registryctl
outpkg: registryctl
# remote interfaces
github.com/docker/distribution:
interfaces:
Manifest:
config:
dir: testing/pkg/distribution

View File

@ -67,7 +67,7 @@ type controllerTestSuite struct {
ctl *controller ctl *controller
repoMgr *repotesting.Manager repoMgr *repotesting.Manager
artMgr *arttesting.Manager artMgr *arttesting.Manager
artrashMgr *artrashtesting.FakeManager artrashMgr *artrashtesting.Manager
blobMgr *blob.Manager blobMgr *blob.Manager
tagCtl *tagtesting.FakeController tagCtl *tagtesting.FakeController
labelMgr *label.Manager labelMgr *label.Manager
@ -80,7 +80,7 @@ type controllerTestSuite struct {
func (c *controllerTestSuite) SetupTest() { func (c *controllerTestSuite) SetupTest() {
c.repoMgr = &repotesting.Manager{} c.repoMgr = &repotesting.Manager{}
c.artMgr = &arttesting.Manager{} c.artMgr = &arttesting.Manager{}
c.artrashMgr = &artrashtesting.FakeManager{} c.artrashMgr = &artrashtesting.Manager{}
c.blobMgr = &blob.Manager{} c.blobMgr = &blob.Manager{}
c.tagCtl = &tagtesting.FakeController{} c.tagCtl = &tagtesting.FakeController{}
c.labelMgr = &label.Manager{} c.labelMgr = &label.Manager{}
@ -476,7 +476,7 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
}, },
}, nil) }, nil)
c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil) c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil)
c.artrashMgr.On("Create").Return(0, nil) c.artrashMgr.On("Create", mock.Anything, mock.Anything).Return(int64(0), nil)
c.accMgr.On("List", mock.Anything, mock.Anything).Return([]accessorymodel.Accessory{}, nil) c.accMgr.On("List", mock.Anything, mock.Anything).Return([]accessorymodel.Accessory{}, nil)
err = c.ctl.deleteDeeply(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, false, false) err = c.ctl.deleteDeeply(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, false, false)
c.Require().Nil(err) c.Require().Nil(err)
@ -534,7 +534,7 @@ func (c *controllerTestSuite) TestDeleteDeeply() {
c.blobMgr.On("List", mock.Anything, mock.Anything).Return(nil, nil) c.blobMgr.On("List", mock.Anything, mock.Anything).Return(nil, nil)
c.blobMgr.On("CleanupAssociationsForProject", mock.Anything, mock.Anything, mock.Anything).Return(nil) c.blobMgr.On("CleanupAssociationsForProject", mock.Anything, mock.Anything, mock.Anything).Return(nil)
c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil) c.repoMgr.On("Get", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{}, nil)
c.artrashMgr.On("Create").Return(0, nil) c.artrashMgr.On("Create", mock.Anything, mock.Anything).Return(int64(0), nil)
err = c.ctl.deleteDeeply(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, true, true) err = c.ctl.deleteDeeply(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, true, true)
c.Require().Nil(err) c.Require().Nil(err)

View File

@ -64,12 +64,12 @@ type processorTestSuite struct {
suite.Suite suite.Suite
processor *processor processor *processor
regCli *registry.Client regCli *registry.Client
chartOptr *chart.FakeOpertaor chartOptr *chart.Operator
} }
func (p *processorTestSuite) SetupTest() { func (p *processorTestSuite) SetupTest() {
p.regCli = &registry.Client{} p.regCli = &registry.Client{}
p.chartOptr = &chart.FakeOpertaor{} p.chartOptr = &chart.Operator{}
p.processor = &processor{ p.processor = &processor{
chartOperator: p.chartOptr, chartOperator: p.chartOptr,
} }
@ -106,7 +106,7 @@ func (p *processorTestSuite) TestAbstractAddition() {
p.Require().Nil(err) p.Require().Nil(err)
p.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(manifest, "", nil) p.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(manifest, "", nil)
p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(chartYaml)), nil) p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(chartYaml)), nil)
p.chartOptr.On("GetDetails").Return(chartDetails, nil) p.chartOptr.On("GetDetails", mock.Anything).Return(chartDetails, nil)
// values.yaml // values.yaml
addition, err := p.processor.AbstractAddition(nil, artifact, AdditionTypeValues) addition, err := p.processor.AbstractAddition(nil, artifact, AdditionTypeValues)

View File

@ -31,8 +31,8 @@ type preheatSuite struct {
suite.Suite suite.Suite
ctx context.Context ctx context.Context
controller Controller controller Controller
fakeInstanceMgr *instance.FakeManager fakeInstanceMgr *instance.Manager
fakePolicyMgr *pmocks.FakeManager fakePolicyMgr *pmocks.Manager
fakeScheduler *smocks.Scheduler fakeScheduler *smocks.Scheduler
mockInstanceServer *httptest.Server mockInstanceServer *httptest.Server
fakeExecutionMgr *tmocks.ExecutionManager fakeExecutionMgr *tmocks.ExecutionManager
@ -40,8 +40,8 @@ type preheatSuite struct {
func TestPreheatSuite(t *testing.T) { func TestPreheatSuite(t *testing.T) {
t.Log("Start TestPreheatSuite") t.Log("Start TestPreheatSuite")
fakeInstanceMgr := &instance.FakeManager{} fakeInstanceMgr := &instance.Manager{}
fakePolicyMgr := &pmocks.FakeManager{} fakePolicyMgr := &pmocks.Manager{}
fakeScheduler := &smocks.Scheduler{} fakeScheduler := &smocks.Scheduler{}
fakeExecutionMgr := &tmocks.ExecutionManager{} fakeExecutionMgr := &tmocks.ExecutionManager{}

View File

@ -70,7 +70,7 @@ func (suite *EnforcerTestSuite) SetupSuite() {
suite.server.StartTLS() suite.server.StartTLS()
fakePolicies := mockPolicies() fakePolicies := mockPolicies()
fakePolicyManager := &policy.FakeManager{} fakePolicyManager := &policy.Manager{}
fakePolicyManager.On("Get", fakePolicyManager.On("Get",
context.TODO(), context.TODO(),
mock.AnythingOfType("int64")). mock.AnythingOfType("int64")).
@ -130,7 +130,7 @@ func (suite *EnforcerTestSuite) SetupSuite() {
}, },
}, nil) }, nil)
fakeInstanceMgr := &instance.FakeManager{} fakeInstanceMgr := &instance.Manager{}
fakeInstanceMgr.On("Get", fakeInstanceMgr.On("Get",
context.TODO(), context.TODO(),
mock.AnythingOfType("int64"), mock.AnythingOfType("int64"),

View File

@ -82,7 +82,7 @@ type ControllerTestSuite struct {
reportMgr *reporttesting.Manager reportMgr *reporttesting.Manager
ar artifact.Controller ar artifact.Controller
c *basicController c *basicController
reportConverter *postprocessorstesting.ScanReportV1ToV2Converter reportConverter *postprocessorstesting.NativeScanReportConverter
cache *mockcache.Cache cache *mockcache.Cache
} }
@ -339,7 +339,7 @@ func (suite *ControllerTestSuite) SetupSuite() {
execMgr: suite.execMgr, execMgr: suite.execMgr,
taskMgr: suite.taskMgr, taskMgr: suite.taskMgr,
reportConverter: &postprocessorstesting.ScanReportV1ToV2Converter{}, reportConverter: &postprocessorstesting.NativeScanReportConverter{},
cache: func() cache.Cache { return suite.cache }, cache: func() cache.Cache { return suite.cache },
} }
mock.OnAnything(suite.scanHandler, "JobVendorType").Return("IMAGE_SCAN") mock.OnAnything(suite.scanHandler, "JobVendorType").Return("IMAGE_SCAN")
@ -486,6 +486,7 @@ func (suite *ControllerTestSuite) TestScanControllerGetReport() {
{ExtraAttrs: suite.makeExtraAttrs(int64(1), "rp-uuid-001")}, {ExtraAttrs: suite.makeExtraAttrs(int64(1), "rp-uuid-001")},
}, nil).Once() }, nil).Once()
mock.OnAnything(suite.accessoryMgr, "List").Return(nil, nil) mock.OnAnything(suite.accessoryMgr, "List").Return(nil, nil)
mock.OnAnything(suite.c.reportConverter, "FromRelationalSchema").Return("", nil)
rep, err := suite.c.GetReport(ctx, suite.artifact, []string{v1.MimeTypeNativeReport}) rep, err := suite.c.GetReport(ctx, suite.artifact, []string{v1.MimeTypeNativeReport})
require.NoError(suite.T(), err) require.NoError(suite.T(), err)
assert.Equal(suite.T(), 1, len(rep)) assert.Equal(suite.T(), 1, len(rep))

View File

@ -51,7 +51,7 @@ type CallbackTestSuite struct {
scanCtl Controller scanCtl Controller
taskMgr *tasktesting.Manager taskMgr *tasktesting.Manager
reportConverter *postprocessorstesting.ScanReportV1ToV2Converter reportConverter *postprocessorstesting.NativeScanReportConverter
} }
func (suite *CallbackTestSuite) SetupSuite() { func (suite *CallbackTestSuite) SetupSuite() {
@ -69,7 +69,7 @@ func (suite *CallbackTestSuite) SetupSuite() {
suite.taskMgr = &tasktesting.Manager{} suite.taskMgr = &tasktesting.Manager{}
taskMgr = suite.taskMgr taskMgr = suite.taskMgr
suite.reportConverter = &postprocessorstesting.ScanReportV1ToV2Converter{} suite.reportConverter = &postprocessorstesting.NativeScanReportConverter{}
suite.scanCtl = &basicController{ suite.scanCtl = &basicController{
makeCtx: context.TODO, makeCtx: context.TODO,

View File

@ -44,7 +44,7 @@ type ControllerTestSuite struct {
c *controller c *controller
scannerMgr *scannerMock.Manager scannerMgr *scannerMock.Manager
secHubMgr *securityMock.Manager secHubMgr *securityMock.Manager
tagMgr *tagMock.FakeManager tagMgr *tagMock.Manager
} }
// TestController is the entry of controller test suite // TestController is the entry of controller test suite
@ -56,7 +56,7 @@ func TestController(t *testing.T) {
func (suite *ControllerTestSuite) SetupTest() { func (suite *ControllerTestSuite) SetupTest() {
suite.secHubMgr = &securityMock.Manager{} suite.secHubMgr = &securityMock.Manager{}
suite.scannerMgr = &scannerMock.Manager{} suite.scannerMgr = &scannerMock.Manager{}
suite.tagMgr = &tagMock.FakeManager{} suite.tagMgr = &tagMock.Manager{}
suite.c = &controller{ suite.c = &controller{
secHubMgr: suite.secHubMgr, secHubMgr: suite.secHubMgr,

View File

@ -18,7 +18,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
@ -27,6 +26,7 @@ import (
_ "github.com/goharbor/harbor/src/pkg/config/inmemory" _ "github.com/goharbor/harbor/src/pkg/config/inmemory"
"github.com/goharbor/harbor/src/pkg/tag/model/tag" "github.com/goharbor/harbor/src/pkg/tag/model/tag"
ormtesting "github.com/goharbor/harbor/src/testing/lib/orm" ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
"github.com/goharbor/harbor/src/testing/mock"
"github.com/goharbor/harbor/src/testing/pkg/artifact" "github.com/goharbor/harbor/src/testing/pkg/artifact"
"github.com/goharbor/harbor/src/testing/pkg/immutable" "github.com/goharbor/harbor/src/testing/pkg/immutable"
"github.com/goharbor/harbor/src/testing/pkg/repository" "github.com/goharbor/harbor/src/testing/pkg/repository"
@ -38,14 +38,14 @@ type controllerTestSuite struct {
ctl *controller ctl *controller
repoMgr *repository.Manager repoMgr *repository.Manager
artMgr *artifact.Manager artMgr *artifact.Manager
tagMgr *tagtesting.FakeManager tagMgr *tagtesting.Manager
immutableMtr *immutable.FakeMatcher immutableMtr *immutable.FakeMatcher
} }
func (c *controllerTestSuite) SetupTest() { func (c *controllerTestSuite) SetupTest() {
c.repoMgr = &repository.Manager{} c.repoMgr = &repository.Manager{}
c.artMgr = &artifact.Manager{} c.artMgr = &artifact.Manager{}
c.tagMgr = &tagtesting.FakeManager{} c.tagMgr = &tagtesting.Manager{}
c.immutableMtr = &immutable.FakeMatcher{} c.immutableMtr = &immutable.FakeMatcher{}
c.ctl = &controller{ c.ctl = &controller{
tagMgr: c.tagMgr, tagMgr: c.tagMgr,
@ -56,7 +56,7 @@ func (c *controllerTestSuite) SetupTest() {
func (c *controllerTestSuite) TestEnsureTag() { func (c *controllerTestSuite) TestEnsureTag() {
// the tag already exists under the repository and is attached to the artifact // the tag already exists under the repository and is attached to the artifact
c.tagMgr.On("List").Return([]*tag.Tag{ c.tagMgr.On("List", mock.Anything, mock.Anything).Return([]*tag.Tag{
{ {
ID: 1, ID: 1,
RepositoryID: 1, RepositoryID: 1,
@ -67,7 +67,7 @@ func (c *controllerTestSuite) TestEnsureTag() {
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{ c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
ID: 1, ID: 1,
}, nil) }, nil)
c.immutableMtr.On("Match").Return(false, nil) mock.OnAnything(c.immutableMtr, "Match").Return(false, nil)
_, err := c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, 1, "latest") _, err := c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, 1, "latest")
c.Require().Nil(err) c.Require().Nil(err)
c.tagMgr.AssertExpectations(c.T()) c.tagMgr.AssertExpectations(c.T())
@ -76,7 +76,7 @@ func (c *controllerTestSuite) TestEnsureTag() {
c.SetupTest() c.SetupTest()
// the tag exists under the repository, but it is attached to other artifact // the tag exists under the repository, but it is attached to other artifact
c.tagMgr.On("List").Return([]*tag.Tag{ c.tagMgr.On("List", mock.Anything, mock.Anything).Return([]*tag.Tag{
{ {
ID: 1, ID: 1,
RepositoryID: 1, RepositoryID: 1,
@ -84,11 +84,11 @@ func (c *controllerTestSuite) TestEnsureTag() {
Name: "latest", Name: "latest",
}, },
}, nil) }, nil)
c.tagMgr.On("Update").Return(nil) c.tagMgr.On("Update", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{ c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
ID: 1, ID: 1,
}, nil) }, nil)
c.immutableMtr.On("Match").Return(false, nil) mock.OnAnything(c.immutableMtr, "Match").Return(false, nil)
_, err = c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, 1, "latest") _, err = c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, 1, "latest")
c.Require().Nil(err) c.Require().Nil(err)
c.tagMgr.AssertExpectations(c.T()) c.tagMgr.AssertExpectations(c.T())
@ -97,26 +97,26 @@ func (c *controllerTestSuite) TestEnsureTag() {
c.SetupTest() c.SetupTest()
// the tag doesn't exist under the repository, create it // the tag doesn't exist under the repository, create it
c.tagMgr.On("List").Return([]*tag.Tag{}, nil) c.tagMgr.On("List", mock.Anything, mock.Anything).Return([]*tag.Tag{}, nil)
c.tagMgr.On("Create").Return(1, nil) c.tagMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), nil)
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{ c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
ID: 1, ID: 1,
}, nil) }, nil)
c.immutableMtr.On("Match").Return(false, nil) mock.OnAnything(c.immutableMtr, "Match").Return(false, nil)
_, err = c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, 1, "latest") _, err = c.ctl.Ensure(orm.NewContext(nil, &ormtesting.FakeOrmer{}), 1, 1, "latest")
c.Require().Nil(err) c.Require().Nil(err)
c.tagMgr.AssertExpectations(c.T()) c.tagMgr.AssertExpectations(c.T())
} }
func (c *controllerTestSuite) TestCount() { func (c *controllerTestSuite) TestCount() {
c.tagMgr.On("Count").Return(1, nil) c.tagMgr.On("Count", mock.Anything, mock.Anything).Return(int64(1), nil)
total, err := c.ctl.Count(nil, nil) total, err := c.ctl.Count(nil, nil)
c.Require().Nil(err) c.Require().Nil(err)
c.Equal(int64(1), total) c.Equal(int64(1), total)
} }
func (c *controllerTestSuite) TestList() { func (c *controllerTestSuite) TestList() {
c.tagMgr.On("List").Return([]*tag.Tag{ c.tagMgr.On("List", mock.Anything, mock.Anything).Return([]*tag.Tag{
{ {
RepositoryID: 1, RepositoryID: 1,
Name: "testlist", Name: "testlist",
@ -134,7 +134,7 @@ func (c *controllerTestSuite) TestGet() {
getTest.RepositoryID = 1 getTest.RepositoryID = 1
getTest.Name = "testget" getTest.Name = "testget"
c.tagMgr.On("Get").Return(getTest, nil) c.tagMgr.On("Get", mock.Anything, mock.Anything).Return(getTest, nil)
tag, err := c.ctl.Get(nil, 1, nil) tag, err := c.ctl.Get(nil, 1, nil)
c.Require().Nil(err) c.Require().Nil(err)
c.tagMgr.AssertExpectations(c.T()) c.tagMgr.AssertExpectations(c.T())
@ -143,36 +143,36 @@ func (c *controllerTestSuite) TestGet() {
} }
func (c *controllerTestSuite) TestDelete() { func (c *controllerTestSuite) TestDelete() {
c.tagMgr.On("Get").Return(&tag.Tag{ c.tagMgr.On("Get", mock.Anything, mock.Anything).Return(&tag.Tag{
RepositoryID: 1, RepositoryID: 1,
Name: "test", Name: "test",
}, nil) }, nil)
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{ c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
ID: 1, ID: 1,
}, nil) }, nil)
c.immutableMtr.On("Match").Return(false, nil) mock.OnAnything(c.immutableMtr, "Match").Return(false, nil)
c.tagMgr.On("Delete").Return(nil) c.tagMgr.On("Delete", mock.Anything, mock.Anything).Return(nil)
err := c.ctl.Delete(nil, 1) err := c.ctl.Delete(nil, 1)
c.Require().Nil(err) c.Require().Nil(err)
} }
func (c *controllerTestSuite) TestDeleteImmutable() { func (c *controllerTestSuite) TestDeleteImmutable() {
c.tagMgr.On("Get").Return(&tag.Tag{ c.tagMgr.On("Get", mock.Anything, mock.Anything).Return(&tag.Tag{
RepositoryID: 1, RepositoryID: 1,
Name: "test", Name: "test",
}, nil) }, nil)
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{ c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
ID: 1, ID: 1,
}, nil) }, nil)
c.immutableMtr.On("Match").Return(true, nil) mock.OnAnything(c.immutableMtr, "Match").Return(true, nil)
c.tagMgr.On("Delete").Return(nil) c.tagMgr.On("Delete", mock.Anything, mock.Anything).Return(nil)
err := c.ctl.Delete(nil, 1) err := c.ctl.Delete(nil, 1)
c.Require().NotNil(err) c.Require().NotNil(err)
c.True(errors.IsErr(err, errors.PreconditionCode)) c.True(errors.IsErr(err, errors.PreconditionCode))
} }
func (c *controllerTestSuite) TestUpdate() { func (c *controllerTestSuite) TestUpdate() {
c.tagMgr.On("Update").Return(nil) mock.OnAnything(c.tagMgr, "Update").Return(nil)
err := c.ctl.Update(nil, &Tag{ err := c.ctl.Update(nil, &Tag{
Tag: tag.Tag{ Tag: tag.Tag{
RepositoryID: 1, RepositoryID: 1,
@ -184,14 +184,14 @@ func (c *controllerTestSuite) TestUpdate() {
} }
func (c *controllerTestSuite) TestDeleteTags() { func (c *controllerTestSuite) TestDeleteTags() {
c.tagMgr.On("Get").Return(&tag.Tag{ c.tagMgr.On("Get", mock.Anything, mock.Anything).Return(&tag.Tag{
RepositoryID: 1, RepositoryID: 1,
}, nil) }, nil)
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{ c.artMgr.On("Get", mock.Anything, mock.Anything).Return(&pkg_artifact.Artifact{
ID: 1, ID: 1,
}, nil) }, nil)
c.immutableMtr.On("Match").Return(false, nil) mock.OnAnything(c.immutableMtr, "Match").Return(false, nil)
c.tagMgr.On("Delete").Return(nil) c.tagMgr.On("Delete", mock.Anything, mock.Anything).Return(nil)
ids := []int64{1, 2, 3, 4} ids := []int64{1, 2, 3, 4}
err := c.ctl.DeleteTags(nil, ids) err := c.ctl.DeleteTags(nil, ids)
c.Require().Nil(err) c.Require().Nil(err)
@ -218,7 +218,7 @@ func (c *controllerTestSuite) TestAssembleTag() {
} }
c.artMgr.On("Get", mock.Anything, mock.Anything).Return(art, nil) c.artMgr.On("Get", mock.Anything, mock.Anything).Return(art, nil)
c.immutableMtr.On("Match").Return(true, nil) mock.OnAnything(c.immutableMtr, "Match").Return(true, nil)
tag := c.ctl.assembleTag(nil, tg, option) tag := c.ctl.assembleTag(nil, tg, option)
c.Require().NotNil(tag) c.Require().NotNil(tag)
c.Equal(tag.ID, tg.ID) c.Equal(tag.ID, tg.ID)

View File

@ -42,8 +42,8 @@ import (
type gcTestSuite struct { type gcTestSuite struct {
htesting.Suite htesting.Suite
artifactCtl *artifacttesting.Controller artifactCtl *artifacttesting.Controller
artrashMgr *trashtesting.FakeManager artrashMgr *trashtesting.Manager
registryCtlClient *registryctl.Mockclient registryCtlClient *registryctl.Client
projectCtl *projecttesting.Controller projectCtl *projecttesting.Controller
blobMgr *blob.Manager blobMgr *blob.Manager
@ -54,8 +54,8 @@ type gcTestSuite struct {
func (suite *gcTestSuite) SetupTest() { func (suite *gcTestSuite) SetupTest() {
suite.artifactCtl = &artifacttesting.Controller{} suite.artifactCtl = &artifacttesting.Controller{}
suite.artrashMgr = &trashtesting.FakeManager{} suite.artrashMgr = &trashtesting.Manager{}
suite.registryCtlClient = &registryctl.Mockclient{} suite.registryCtlClient = &registryctl.Client{}
suite.blobMgr = &blob.Manager{} suite.blobMgr = &blob.Manager{}
suite.projectCtl = &projecttesting.Controller{} suite.projectCtl = &projecttesting.Controller{}
@ -98,7 +98,7 @@ func (suite *gcTestSuite) TestDeletedArt() {
}, },
}, nil) }, nil)
suite.artifactCtl.On("Delete").Return(nil) suite.artifactCtl.On("Delete").Return(nil)
suite.artrashMgr.On("Filter").Return([]model.ArtifactTrash{ mock.OnAnything(suite.artrashMgr, "Filter").Return([]model.ArtifactTrash{
{ {
ID: 1, ID: 1,
Digest: suite.DigestString(), Digest: suite.DigestString(),
@ -163,6 +163,8 @@ func (suite *gcTestSuite) TestInit() {
"time_window": 1, "time_window": 1,
"workers": float64(3), "workers": float64(3),
} }
mock.OnAnything(gc.registryCtlClient, "Health").Return(nil)
suite.Nil(gc.init(ctx, params)) suite.Nil(gc.init(ctx, params))
suite.True(gc.deleteUntagged) suite.True(gc.deleteUntagged)
suite.Equal(3, gc.workers) suite.Equal(3, gc.workers)
@ -230,7 +232,7 @@ func (suite *gcTestSuite) TestRun() {
}, },
}, nil) }, nil)
suite.artifactCtl.On("Delete").Return(nil) suite.artifactCtl.On("Delete").Return(nil)
suite.artrashMgr.On("Filter").Return([]model.ArtifactTrash{}, nil) mock.OnAnything(suite.artrashMgr, "Filter").Return([]model.ArtifactTrash{}, nil)
mock.OnAnything(suite.projectCtl, "List").Return([]*proModels.Project{ mock.OnAnything(suite.projectCtl, "List").Return([]*proModels.Project{
{ {
@ -271,6 +273,8 @@ func (suite *gcTestSuite) TestRun() {
mock.OnAnything(suite.blobMgr, "Delete").Return(nil) mock.OnAnything(suite.blobMgr, "Delete").Return(nil)
mock.OnAnything(suite.registryCtlClient, "Health").Return(nil)
gc := &GarbageCollector{ gc := &GarbageCollector{
artCtl: suite.artifactCtl, artCtl: suite.artifactCtl,
artrashMgr: suite.artrashMgr, artrashMgr: suite.artrashMgr,
@ -284,6 +288,7 @@ func (suite *gcTestSuite) TestRun() {
"workers": 3, "workers": 3,
} }
mock.OnAnything(gc.registryCtlClient, "DeleteBlob").Return(nil)
suite.Nil(gc.Run(ctx, params)) suite.Nil(gc.Run(ctx, params))
} }
@ -302,7 +307,7 @@ func (suite *gcTestSuite) TestMark() {
}, },
}, nil) }, nil)
suite.artifactCtl.On("Delete").Return(nil) suite.artifactCtl.On("Delete").Return(nil)
suite.artrashMgr.On("Filter").Return([]model.ArtifactTrash{ mock.OnAnything(suite.artrashMgr, "Filter").Return([]model.ArtifactTrash{
{ {
ID: 1, ID: 1,
Digest: suite.DigestString(), Digest: suite.DigestString(),
@ -381,6 +386,7 @@ func (suite *gcTestSuite) TestSweep() {
workers: 3, workers: 3,
} }
mock.OnAnything(gc.registryCtlClient, "DeleteBlob").Return(nil)
suite.Nil(gc.sweep(ctx)) suite.Nil(gc.sweep(ctx))
} }

View File

@ -62,12 +62,12 @@ func TestPostScan(t *testing.T) {
origRp := &scan.Report{} origRp := &scan.Report{}
rawReport := "" rawReport := ""
mocker := &postprocessorstesting.ScanReportV1ToV2Converter{} mocker := &postprocessorstesting.NativeScanReportConverter{}
mocker.On("ToRelationalSchema", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, "original report", nil) mocker.On("ToRelationalSchema", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("", "original report", nil)
postprocessors.Converter = mocker postprocessors.Converter = mocker
sr := &v1.ScanRequest{Artifact: artifact} sr := &v1.ScanRequest{Artifact: artifact}
refreshedReport, err := v.PostScan(ctx, sr, origRp, rawReport, time.Now(), &model.Robot{}) refreshedReport, err := v.PostScan(ctx, sr, origRp, rawReport, time.Now(), &model.Robot{})
assert.Equal(t, "", refreshedReport, "PostScan should return the refreshed report") assert.Equal(t, "original report", refreshedReport, "PostScan should return the refreshed report")
assert.Nil(t, err, "PostScan should not return an error") assert.Nil(t, err, "PostScan should not return an error")
} }
@ -209,6 +209,7 @@ func (suite *VulHandlerTestSuite) TestMakeReportPlaceHolder() {
mock.OnAnything(suite.reportMgr, "Create").Return("uuid", nil).Once() mock.OnAnything(suite.reportMgr, "Create").Return("uuid", nil).Once()
mock.OnAnything(suite.reportMgr, "Delete").Return(nil).Once() mock.OnAnything(suite.reportMgr, "Delete").Return(nil).Once()
mock.OnAnything(suite.taskMgr, "ListScanTasksByReportUUID").Return([]*task.Task{{Status: "Success"}}, nil) mock.OnAnything(suite.taskMgr, "ListScanTasksByReportUUID").Return([]*task.Task{{Status: "Success"}}, nil)
mock.OnAnything(suite.handler.reportConverter, "FromRelationalSchema").Return("", nil)
rps, err := suite.handler.MakePlaceHolder(ctx, art, r) rps, err := suite.handler.MakePlaceHolder(ctx, art, r)
require.NoError(suite.T(), err) require.NoError(suite.T(), err)
assert.Equal(suite.T(), 1, len(rps)) assert.Equal(suite.T(), 1, len(rps))

View File

@ -1,136 +0,0 @@
// Code generated by mockery v2.22.1. DO NOT EDIT.
package libcache
import (
context "context"
cache "github.com/goharbor/harbor/src/lib/cache"
mock "github.com/stretchr/testify/mock"
time "time"
)
// Cache is an autogenerated mock type for the Cache type
type Cache struct {
mock.Mock
}
// Contains provides a mock function with given fields: ctx, key
func (_m *Cache) Contains(ctx context.Context, key string) bool {
ret := _m.Called(ctx, key)
var r0 bool
if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok {
r0 = rf(ctx, key)
} else {
r0 = ret.Get(0).(bool)
}
return r0
}
// Delete provides a mock function with given fields: ctx, key
func (_m *Cache) Delete(ctx context.Context, key string) error {
ret := _m.Called(ctx, key)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
r0 = rf(ctx, key)
} else {
r0 = ret.Error(0)
}
return r0
}
// Fetch provides a mock function with given fields: ctx, key, value
func (_m *Cache) Fetch(ctx context.Context, key string, value interface{}) error {
ret := _m.Called(ctx, key, value)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok {
r0 = rf(ctx, key, value)
} else {
r0 = ret.Error(0)
}
return r0
}
// Ping provides a mock function with given fields: ctx
func (_m *Cache) Ping(ctx context.Context) error {
ret := _m.Called(ctx)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = rf(ctx)
} else {
r0 = ret.Error(0)
}
return r0
}
// Save provides a mock function with given fields: ctx, key, value, expiration
func (_m *Cache) Save(ctx context.Context, key string, value interface{}, expiration ...time.Duration) error {
_va := make([]interface{}, len(expiration))
for _i := range expiration {
_va[_i] = expiration[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, key, value)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, interface{}, ...time.Duration) error); ok {
r0 = rf(ctx, key, value, expiration...)
} else {
r0 = ret.Error(0)
}
return r0
}
// Scan provides a mock function with given fields: ctx, match
func (_m *Cache) Scan(ctx context.Context, match string) (cache.Iterator, error) {
ret := _m.Called(ctx, match)
var r0 cache.Iterator
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (cache.Iterator, error)); ok {
return rf(ctx, match)
}
if rf, ok := ret.Get(0).(func(context.Context, string) cache.Iterator); ok {
r0 = rf(ctx, match)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(cache.Iterator)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, match)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
type mockConstructorTestingTNewCache interface {
mock.TestingT
Cleanup(func())
}
// NewCache creates a new instance of Cache. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewCache(t mockConstructorTestingTNewCache) *Cache {
mock := &Cache{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,38 +1,123 @@
// Code generated by mockery v2.43.2. DO NOT EDIT.
package artifactrash package artifactrash
import ( import (
"context" context "context"
"github.com/stretchr/testify/mock" model "github.com/goharbor/harbor/src/pkg/artifactrash/model"
mock "github.com/stretchr/testify/mock"
"github.com/goharbor/harbor/src/pkg/artifactrash/model"
) )
// FakeManager is a fake tag manager that implement the src/pkg/tag.Manager interface // Manager is an autogenerated mock type for the Manager type
type FakeManager struct { type Manager struct {
mock.Mock mock.Mock
} }
// Create ... // Create provides a mock function with given fields: ctx, artifactrsh
func (f *FakeManager) Create(ctx context.Context, artifactrsh *model.ArtifactTrash) (id int64, err error) { func (_m *Manager) Create(ctx context.Context, artifactrsh *model.ArtifactTrash) (int64, error) {
args := f.Called() ret := _m.Called(ctx, artifactrsh)
return int64(args.Int(0)), args.Error(1)
if len(ret) == 0 {
panic("no return value specified for Create")
}
var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *model.ArtifactTrash) (int64, error)); ok {
return rf(ctx, artifactrsh)
}
if rf, ok := ret.Get(0).(func(context.Context, *model.ArtifactTrash) int64); ok {
r0 = rf(ctx, artifactrsh)
} else {
r0 = ret.Get(0).(int64)
}
if rf, ok := ret.Get(1).(func(context.Context, *model.ArtifactTrash) error); ok {
r1 = rf(ctx, artifactrsh)
} else {
r1 = ret.Error(1)
}
return r0, r1
} }
// Delete ... // Delete provides a mock function with given fields: ctx, id
func (f *FakeManager) Delete(ctx context.Context, id int64) error { func (_m *Manager) Delete(ctx context.Context, id int64) error {
args := f.Called() ret := _m.Called(ctx, id)
return args.Error(0)
if len(ret) == 0 {
panic("no return value specified for Delete")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
r0 = rf(ctx, id)
} else {
r0 = ret.Error(0)
}
return r0
} }
// Filter ... // Filter provides a mock function with given fields: ctx, timeWindow
func (f *FakeManager) Filter(ctx context.Context, timeWindow int64) (arts []model.ArtifactTrash, err error) { func (_m *Manager) Filter(ctx context.Context, timeWindow int64) ([]model.ArtifactTrash, error) {
args := f.Called() ret := _m.Called(ctx, timeWindow)
return args.Get(0).([]model.ArtifactTrash), args.Error(1)
if len(ret) == 0 {
panic("no return value specified for Filter")
}
var r0 []model.ArtifactTrash
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64) ([]model.ArtifactTrash, error)); ok {
return rf(ctx, timeWindow)
}
if rf, ok := ret.Get(0).(func(context.Context, int64) []model.ArtifactTrash); ok {
r0 = rf(ctx, timeWindow)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]model.ArtifactTrash)
}
}
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
r1 = rf(ctx, timeWindow)
} else {
r1 = ret.Error(1)
}
return r0, r1
} }
// Flush ... // Flush provides a mock function with given fields: ctx, timeWindow
func (f *FakeManager) Flush(ctx context.Context, timeWindow int64) (err error) { func (_m *Manager) Flush(ctx context.Context, timeWindow int64) error {
args := f.Called() ret := _m.Called(ctx, timeWindow)
return args.Error(0)
if len(ret) == 0 {
panic("no return value specified for Flush")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
r0 = rf(ctx, timeWindow)
} else {
r0 = ret.Error(0)
}
return r0
}
// NewManager creates a new instance of Manager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewManager(t interface {
mock.TestingT
Cleanup(func())
}) *Manager {
mock := &Manager{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
} }

View File

@ -1,33 +1,89 @@
// Code generated by mockery v2.43.2. DO NOT EDIT.
package chart package chart
import ( import (
"github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
helm_chart "helm.sh/helm/v3/pkg/chart" chart "helm.sh/helm/v3/pkg/chart"
chartserver "github.com/goharbor/harbor/src/pkg/chart" pkgchart "github.com/goharbor/harbor/src/pkg/chart"
) )
// FakeOpertaor ... // Operator is an autogenerated mock type for the Operator type
type FakeOpertaor struct { type Operator struct {
mock.Mock mock.Mock
} }
// GetDetails ... // GetData provides a mock function with given fields: content
func (f *FakeOpertaor) GetDetails(content []byte) (*chartserver.VersionDetails, error) { func (_m *Operator) GetData(content []byte) (*chart.Chart, error) {
args := f.Called() ret := _m.Called(content)
var chartDetails *chartserver.VersionDetails
if args.Get(0) != nil { if len(ret) == 0 {
chartDetails = args.Get(0).(*chartserver.VersionDetails) panic("no return value specified for GetData")
} }
return chartDetails, args.Error(1)
var r0 *chart.Chart
var r1 error
if rf, ok := ret.Get(0).(func([]byte) (*chart.Chart, error)); ok {
return rf(content)
}
if rf, ok := ret.Get(0).(func([]byte) *chart.Chart); ok {
r0 = rf(content)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*chart.Chart)
}
}
if rf, ok := ret.Get(1).(func([]byte) error); ok {
r1 = rf(content)
} else {
r1 = ret.Error(1)
}
return r0, r1
} }
// GetData ... // GetDetails provides a mock function with given fields: content
func (f *FakeOpertaor) GetData(content []byte) (*helm_chart.Chart, error) { func (_m *Operator) GetDetails(content []byte) (*pkgchart.VersionDetails, error) {
args := f.Called() ret := _m.Called(content)
var chartData *helm_chart.Chart
if args.Get(0) != nil { if len(ret) == 0 {
chartData = args.Get(0).(*helm_chart.Chart) panic("no return value specified for GetDetails")
} }
return chartData, args.Error(1)
var r0 *pkgchart.VersionDetails
var r1 error
if rf, ok := ret.Get(0).(func([]byte) (*pkgchart.VersionDetails, error)); ok {
return rf(content)
}
if rf, ok := ret.Get(0).(func([]byte) *pkgchart.VersionDetails); ok {
r0 = rf(content)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*pkgchart.VersionDetails)
}
}
if rf, ok := ret.Get(1).(func([]byte) error); ok {
r1 = rf(content)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewOperator creates a new instance of Operator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewOperator(t interface {
mock.TestingT
Cleanup(func())
}) *Operator {
mock := &Operator{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
} }

View File

@ -1,4 +1,4 @@
// Code generated by mockery v2.22.1. DO NOT EDIT. // Code generated by mockery v2.43.2. DO NOT EDIT.
package distribution package distribution
@ -16,6 +16,10 @@ type Manifest struct {
func (_m *Manifest) Payload() (string, []byte, error) { func (_m *Manifest) Payload() (string, []byte, error) {
ret := _m.Called() ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Payload")
}
var r0 string var r0 string
var r1 []byte var r1 []byte
var r2 error var r2 error
@ -49,6 +53,10 @@ func (_m *Manifest) Payload() (string, []byte, error) {
func (_m *Manifest) References() []distribution.Descriptor { func (_m *Manifest) References() []distribution.Descriptor {
ret := _m.Called() ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for References")
}
var r0 []distribution.Descriptor var r0 []distribution.Descriptor
if rf, ok := ret.Get(0).(func() []distribution.Descriptor); ok { if rf, ok := ret.Get(0).(func() []distribution.Descriptor); ok {
r0 = rf() r0 = rf()
@ -61,13 +69,12 @@ func (_m *Manifest) References() []distribution.Descriptor {
return r0 return r0
} }
type mockConstructorTestingTNewManifest interface { // NewManifest creates a new instance of Manifest. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewManifest(t interface {
mock.TestingT mock.TestingT
Cleanup(func()) Cleanup(func())
} }) *Manifest {
// NewManifest creates a new instance of Manifest. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewManifest(t mockConstructorTestingTNewManifest) *Manifest {
mock := &Manifest{} mock := &Manifest{}
mock.Mock.Test(t) mock.Mock.Test(t)

View File

@ -1,20 +1,58 @@
// Code generated by mockery v2.43.2. DO NOT EDIT.
package immutable package immutable
import ( import (
"context" context "context"
"github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
"github.com/goharbor/harbor/src/lib/selector" selector "github.com/goharbor/harbor/src/lib/selector"
) )
// FakeMatcher ... // FakeMatcher is an autogenerated mock type for the ImmutableTagMatcher type
type FakeMatcher struct { type FakeMatcher struct {
mock.Mock mock.Mock
} }
// Match ... // Match provides a mock function with given fields: ctx, pid, c
func (f *FakeMatcher) Match(ctx context.Context, pid int64, c selector.Candidate) (bool, error) { func (_m *FakeMatcher) Match(ctx context.Context, pid int64, c selector.Candidate) (bool, error) {
args := f.Called() ret := _m.Called(ctx, pid, c)
return args.Bool(0), args.Error(1)
if len(ret) == 0 {
panic("no return value specified for Match")
}
var r0 bool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64, selector.Candidate) (bool, error)); ok {
return rf(ctx, pid, c)
}
if rf, ok := ret.Get(0).(func(context.Context, int64, selector.Candidate) bool); ok {
r0 = rf(ctx, pid, c)
} else {
r0 = ret.Get(0).(bool)
}
if rf, ok := ret.Get(1).(func(context.Context, int64, selector.Candidate) error); ok {
r1 = rf(ctx, pid, c)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewFakeMatcher creates a new instance of FakeMatcher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewFakeMatcher(t interface {
mock.TestingT
Cleanup(func())
}) *FakeMatcher {
mock := &FakeMatcher{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
} }

View File

@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0. DO NOT EDIT. // Code generated by mockery v2.43.2. DO NOT EDIT.
package instance package instance
@ -7,27 +7,35 @@ import (
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
q "github.com/goharbor/harbor/src/lib/q"
provider "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider" provider "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider"
q "github.com/goharbor/harbor/src/lib/q"
) )
// FakeManager is an autogenerated mock type for the Manager type // Manager is an autogenerated mock type for the Manager type
type FakeManager struct { type Manager struct {
mock.Mock mock.Mock
} }
// Count provides a mock function with given fields: ctx, query // Count provides a mock function with given fields: ctx, query
func (_m *FakeManager) Count(ctx context.Context, query *q.Query) (int64, error) { func (_m *Manager) Count(ctx context.Context, query *q.Query) (int64, error) {
ret := _m.Called(ctx, query) ret := _m.Called(ctx, query)
if len(ret) == 0 {
panic("no return value specified for Count")
}
var r0 int64 var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) (int64, error)); ok {
return rf(ctx, query)
}
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) int64); ok { if rf, ok := ret.Get(0).(func(context.Context, *q.Query) int64); ok {
r0 = rf(ctx, query) r0 = rf(ctx, query)
} else { } else {
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query) r1 = rf(ctx, query)
} else { } else {
@ -38,9 +46,13 @@ func (_m *FakeManager) Count(ctx context.Context, query *q.Query) (int64, error)
} }
// Delete provides a mock function with given fields: ctx, id // Delete provides a mock function with given fields: ctx, id
func (_m *FakeManager) Delete(ctx context.Context, id int64) error { func (_m *Manager) Delete(ctx context.Context, id int64) error {
ret := _m.Called(ctx, id) ret := _m.Called(ctx, id)
if len(ret) == 0 {
panic("no return value specified for Delete")
}
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
r0 = rf(ctx, id) r0 = rf(ctx, id)
@ -52,10 +64,18 @@ func (_m *FakeManager) Delete(ctx context.Context, id int64) error {
} }
// Get provides a mock function with given fields: ctx, id // Get provides a mock function with given fields: ctx, id
func (_m *FakeManager) Get(ctx context.Context, id int64) (*provider.Instance, error) { func (_m *Manager) Get(ctx context.Context, id int64) (*provider.Instance, error) {
ret := _m.Called(ctx, id) ret := _m.Called(ctx, id)
if len(ret) == 0 {
panic("no return value specified for Get")
}
var r0 *provider.Instance var r0 *provider.Instance
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64) (*provider.Instance, error)); ok {
return rf(ctx, id)
}
if rf, ok := ret.Get(0).(func(context.Context, int64) *provider.Instance); ok { if rf, ok := ret.Get(0).(func(context.Context, int64) *provider.Instance); ok {
r0 = rf(ctx, id) r0 = rf(ctx, id)
} else { } else {
@ -64,7 +84,6 @@ func (_m *FakeManager) Get(ctx context.Context, id int64) (*provider.Instance, e
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
r1 = rf(ctx, id) r1 = rf(ctx, id)
} else { } else {
@ -75,10 +94,18 @@ func (_m *FakeManager) Get(ctx context.Context, id int64) (*provider.Instance, e
} }
// GetByName provides a mock function with given fields: ctx, name // GetByName provides a mock function with given fields: ctx, name
func (_m *FakeManager) GetByName(ctx context.Context, name string) (*provider.Instance, error) { func (_m *Manager) GetByName(ctx context.Context, name string) (*provider.Instance, error) {
ret := _m.Called(ctx, name) ret := _m.Called(ctx, name)
if len(ret) == 0 {
panic("no return value specified for GetByName")
}
var r0 *provider.Instance var r0 *provider.Instance
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (*provider.Instance, error)); ok {
return rf(ctx, name)
}
if rf, ok := ret.Get(0).(func(context.Context, string) *provider.Instance); ok { if rf, ok := ret.Get(0).(func(context.Context, string) *provider.Instance); ok {
r0 = rf(ctx, name) r0 = rf(ctx, name)
} else { } else {
@ -87,7 +114,6 @@ func (_m *FakeManager) GetByName(ctx context.Context, name string) (*provider.In
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, name) r1 = rf(ctx, name)
} else { } else {
@ -98,10 +124,18 @@ func (_m *FakeManager) GetByName(ctx context.Context, name string) (*provider.In
} }
// List provides a mock function with given fields: ctx, query // List provides a mock function with given fields: ctx, query
func (_m *FakeManager) List(ctx context.Context, query *q.Query) ([]*provider.Instance, error) { func (_m *Manager) List(ctx context.Context, query *q.Query) ([]*provider.Instance, error) {
ret := _m.Called(ctx, query) ret := _m.Called(ctx, query)
if len(ret) == 0 {
panic("no return value specified for List")
}
var r0 []*provider.Instance var r0 []*provider.Instance
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) ([]*provider.Instance, error)); ok {
return rf(ctx, query)
}
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) []*provider.Instance); ok { if rf, ok := ret.Get(0).(func(context.Context, *q.Query) []*provider.Instance); ok {
r0 = rf(ctx, query) r0 = rf(ctx, query)
} else { } else {
@ -110,7 +144,6 @@ func (_m *FakeManager) List(ctx context.Context, query *q.Query) ([]*provider.In
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query) r1 = rf(ctx, query)
} else { } else {
@ -121,17 +154,24 @@ func (_m *FakeManager) List(ctx context.Context, query *q.Query) ([]*provider.In
} }
// Save provides a mock function with given fields: ctx, inst // Save provides a mock function with given fields: ctx, inst
func (_m *FakeManager) Save(ctx context.Context, inst *provider.Instance) (int64, error) { func (_m *Manager) Save(ctx context.Context, inst *provider.Instance) (int64, error) {
ret := _m.Called(ctx, inst) ret := _m.Called(ctx, inst)
if len(ret) == 0 {
panic("no return value specified for Save")
}
var r0 int64 var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *provider.Instance) (int64, error)); ok {
return rf(ctx, inst)
}
if rf, ok := ret.Get(0).(func(context.Context, *provider.Instance) int64); ok { if rf, ok := ret.Get(0).(func(context.Context, *provider.Instance) int64); ok {
r0 = rf(ctx, inst) r0 = rf(ctx, inst)
} else { } else {
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *provider.Instance) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *provider.Instance) error); ok {
r1 = rf(ctx, inst) r1 = rf(ctx, inst)
} else { } else {
@ -142,7 +182,7 @@ func (_m *FakeManager) Save(ctx context.Context, inst *provider.Instance) (int64
} }
// Update provides a mock function with given fields: ctx, inst, props // Update provides a mock function with given fields: ctx, inst, props
func (_m *FakeManager) Update(ctx context.Context, inst *provider.Instance, props ...string) error { func (_m *Manager) Update(ctx context.Context, inst *provider.Instance, props ...string) error {
_va := make([]interface{}, len(props)) _va := make([]interface{}, len(props))
for _i := range props { for _i := range props {
_va[_i] = props[_i] _va[_i] = props[_i]
@ -152,6 +192,10 @@ func (_m *FakeManager) Update(ctx context.Context, inst *provider.Instance, prop
_ca = append(_ca, _va...) _ca = append(_ca, _va...)
ret := _m.Called(_ca...) ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for Update")
}
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *provider.Instance, ...string) error); ok { if rf, ok := ret.Get(0).(func(context.Context, *provider.Instance, ...string) error); ok {
r0 = rf(ctx, inst, props...) r0 = rf(ctx, inst, props...)
@ -161,3 +205,17 @@ func (_m *FakeManager) Update(ctx context.Context, inst *provider.Instance, prop
return r0 return r0
} }
// NewManager creates a new instance of Manager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewManager(t interface {
mock.TestingT
Cleanup(func())
}) *Manager {
mock := &Manager{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,33 +1,40 @@
// Code generated by mockery v2.0.3. DO NOT EDIT. // Code generated by mockery v2.43.2. DO NOT EDIT.
package policy package policy
import ( import (
context "context" context "context"
modelspolicy "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/policy"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
q "github.com/goharbor/harbor/src/lib/q" q "github.com/goharbor/harbor/src/lib/q"
modelspolicy "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/policy"
) )
// FakeManager is an autogenerated mock type for the Manager type // Manager is an autogenerated mock type for the Manager type
type FakeManager struct { type Manager struct {
mock.Mock mock.Mock
} }
// Count provides a mock function with given fields: ctx, query // Count provides a mock function with given fields: ctx, query
func (_m *FakeManager) Count(ctx context.Context, query *q.Query) (int64, error) { func (_m *Manager) Count(ctx context.Context, query *q.Query) (int64, error) {
ret := _m.Called(ctx, query) ret := _m.Called(ctx, query)
if len(ret) == 0 {
panic("no return value specified for Count")
}
var r0 int64 var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) (int64, error)); ok {
return rf(ctx, query)
}
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) int64); ok { if rf, ok := ret.Get(0).(func(context.Context, *q.Query) int64); ok {
r0 = rf(ctx, query) r0 = rf(ctx, query)
} else { } else {
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query) r1 = rf(ctx, query)
} else { } else {
@ -38,17 +45,24 @@ func (_m *FakeManager) Count(ctx context.Context, query *q.Query) (int64, error)
} }
// Create provides a mock function with given fields: ctx, schema // Create provides a mock function with given fields: ctx, schema
func (_m *FakeManager) Create(ctx context.Context, schema *modelspolicy.Schema) (int64, error) { func (_m *Manager) Create(ctx context.Context, schema *modelspolicy.Schema) (int64, error) {
ret := _m.Called(ctx, schema) ret := _m.Called(ctx, schema)
if len(ret) == 0 {
panic("no return value specified for Create")
}
var r0 int64 var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *modelspolicy.Schema) (int64, error)); ok {
return rf(ctx, schema)
}
if rf, ok := ret.Get(0).(func(context.Context, *modelspolicy.Schema) int64); ok { if rf, ok := ret.Get(0).(func(context.Context, *modelspolicy.Schema) int64); ok {
r0 = rf(ctx, schema) r0 = rf(ctx, schema)
} else { } else {
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *modelspolicy.Schema) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *modelspolicy.Schema) error); ok {
r1 = rf(ctx, schema) r1 = rf(ctx, schema)
} else { } else {
@ -59,9 +73,13 @@ func (_m *FakeManager) Create(ctx context.Context, schema *modelspolicy.Schema)
} }
// Delete provides a mock function with given fields: ctx, id // Delete provides a mock function with given fields: ctx, id
func (_m *FakeManager) Delete(ctx context.Context, id int64) error { func (_m *Manager) Delete(ctx context.Context, id int64) error {
ret := _m.Called(ctx, id) ret := _m.Called(ctx, id)
if len(ret) == 0 {
panic("no return value specified for Delete")
}
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
r0 = rf(ctx, id) r0 = rf(ctx, id)
@ -73,10 +91,18 @@ func (_m *FakeManager) Delete(ctx context.Context, id int64) error {
} }
// Get provides a mock function with given fields: ctx, id // Get provides a mock function with given fields: ctx, id
func (_m *FakeManager) Get(ctx context.Context, id int64) (*modelspolicy.Schema, error) { func (_m *Manager) Get(ctx context.Context, id int64) (*modelspolicy.Schema, error) {
ret := _m.Called(ctx, id) ret := _m.Called(ctx, id)
if len(ret) == 0 {
panic("no return value specified for Get")
}
var r0 *modelspolicy.Schema var r0 *modelspolicy.Schema
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64) (*modelspolicy.Schema, error)); ok {
return rf(ctx, id)
}
if rf, ok := ret.Get(0).(func(context.Context, int64) *modelspolicy.Schema); ok { if rf, ok := ret.Get(0).(func(context.Context, int64) *modelspolicy.Schema); ok {
r0 = rf(ctx, id) r0 = rf(ctx, id)
} else { } else {
@ -85,7 +111,6 @@ func (_m *FakeManager) Get(ctx context.Context, id int64) (*modelspolicy.Schema,
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
r1 = rf(ctx, id) r1 = rf(ctx, id)
} else { } else {
@ -95,22 +120,29 @@ func (_m *FakeManager) Get(ctx context.Context, id int64) (*modelspolicy.Schema,
return r0, r1 return r0, r1
} }
// GetByName provides a mock function with given fields: ctx, projectId, name // GetByName provides a mock function with given fields: ctx, projectID, name
func (_m *FakeManager) GetByName(ctx context.Context, projectId int64, name string) (*modelspolicy.Schema, error) { func (_m *Manager) GetByName(ctx context.Context, projectID int64, name string) (*modelspolicy.Schema, error) {
ret := _m.Called(ctx, projectId, name) ret := _m.Called(ctx, projectID, name)
if len(ret) == 0 {
panic("no return value specified for GetByName")
}
var r0 *modelspolicy.Schema var r0 *modelspolicy.Schema
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64, string) (*modelspolicy.Schema, error)); ok {
return rf(ctx, projectID, name)
}
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *modelspolicy.Schema); ok { if rf, ok := ret.Get(0).(func(context.Context, int64, string) *modelspolicy.Schema); ok {
r0 = rf(ctx, projectId, name) r0 = rf(ctx, projectID, name)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*modelspolicy.Schema) r0 = ret.Get(0).(*modelspolicy.Schema)
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok {
r1 = rf(ctx, projectId, name) r1 = rf(ctx, projectID, name)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
} }
@ -119,10 +151,18 @@ func (_m *FakeManager) GetByName(ctx context.Context, projectId int64, name stri
} }
// ListPolicies provides a mock function with given fields: ctx, query // ListPolicies provides a mock function with given fields: ctx, query
func (_m *FakeManager) ListPolicies(ctx context.Context, query *q.Query) ([]*modelspolicy.Schema, error) { func (_m *Manager) ListPolicies(ctx context.Context, query *q.Query) ([]*modelspolicy.Schema, error) {
ret := _m.Called(ctx, query) ret := _m.Called(ctx, query)
if len(ret) == 0 {
panic("no return value specified for ListPolicies")
}
var r0 []*modelspolicy.Schema var r0 []*modelspolicy.Schema
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) ([]*modelspolicy.Schema, error)); ok {
return rf(ctx, query)
}
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) []*modelspolicy.Schema); ok { if rf, ok := ret.Get(0).(func(context.Context, *q.Query) []*modelspolicy.Schema); ok {
r0 = rf(ctx, query) r0 = rf(ctx, query)
} else { } else {
@ -131,7 +171,6 @@ func (_m *FakeManager) ListPolicies(ctx context.Context, query *q.Query) ([]*mod
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query) r1 = rf(ctx, query)
} else { } else {
@ -142,10 +181,18 @@ func (_m *FakeManager) ListPolicies(ctx context.Context, query *q.Query) ([]*mod
} }
// ListPoliciesByProject provides a mock function with given fields: ctx, project, query // ListPoliciesByProject provides a mock function with given fields: ctx, project, query
func (_m *FakeManager) ListPoliciesByProject(ctx context.Context, project int64, query *q.Query) ([]*modelspolicy.Schema, error) { func (_m *Manager) ListPoliciesByProject(ctx context.Context, project int64, query *q.Query) ([]*modelspolicy.Schema, error) {
ret := _m.Called(ctx, project, query) ret := _m.Called(ctx, project, query)
if len(ret) == 0 {
panic("no return value specified for ListPoliciesByProject")
}
var r0 []*modelspolicy.Schema var r0 []*modelspolicy.Schema
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64, *q.Query) ([]*modelspolicy.Schema, error)); ok {
return rf(ctx, project, query)
}
if rf, ok := ret.Get(0).(func(context.Context, int64, *q.Query) []*modelspolicy.Schema); ok { if rf, ok := ret.Get(0).(func(context.Context, int64, *q.Query) []*modelspolicy.Schema); ok {
r0 = rf(ctx, project, query) r0 = rf(ctx, project, query)
} else { } else {
@ -154,7 +201,6 @@ func (_m *FakeManager) ListPoliciesByProject(ctx context.Context, project int64,
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, int64, *q.Query) error); ok { if rf, ok := ret.Get(1).(func(context.Context, int64, *q.Query) error); ok {
r1 = rf(ctx, project, query) r1 = rf(ctx, project, query)
} else { } else {
@ -165,7 +211,7 @@ func (_m *FakeManager) ListPoliciesByProject(ctx context.Context, project int64,
} }
// Update provides a mock function with given fields: ctx, schema, props // Update provides a mock function with given fields: ctx, schema, props
func (_m *FakeManager) Update(ctx context.Context, schema *modelspolicy.Schema, props ...string) error { func (_m *Manager) Update(ctx context.Context, schema *modelspolicy.Schema, props ...string) error {
_va := make([]interface{}, len(props)) _va := make([]interface{}, len(props))
for _i := range props { for _i := range props {
_va[_i] = props[_i] _va[_i] = props[_i]
@ -175,6 +221,10 @@ func (_m *FakeManager) Update(ctx context.Context, schema *modelspolicy.Schema,
_ca = append(_ca, _va...) _ca = append(_ca, _va...)
ret := _m.Called(_ca...) ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for Update")
}
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *modelspolicy.Schema, ...string) error); ok { if rf, ok := ret.Get(0).(func(context.Context, *modelspolicy.Schema, ...string) error); ok {
r0 = rf(ctx, schema, props...) r0 = rf(ctx, schema, props...)
@ -184,3 +234,17 @@ func (_m *FakeManager) Update(ctx context.Context, schema *modelspolicy.Schema,
return r0 return r0
} }
// NewManager creates a new instance of Manager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewManager(t interface {
mock.TestingT
Cleanup(func())
}) *Manager {
mock := &Manager{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,13 +1,13 @@
// Code generated by mockery v2.1.0. DO NOT EDIT. // Code generated by mockery v2.43.2. DO NOT EDIT.
package parser package parser
import ( import (
context "context" context "context"
mock "github.com/stretchr/testify/mock"
artifact "github.com/goharbor/harbor/src/pkg/artifact" artifact "github.com/goharbor/harbor/src/pkg/artifact"
mock "github.com/stretchr/testify/mock"
) )
// Parser is an autogenerated mock type for the Parser type // Parser is an autogenerated mock type for the Parser type
@ -19,6 +19,10 @@ type Parser struct {
func (_m *Parser) Parse(ctx context.Context, _a1 *artifact.Artifact, manifest []byte) error { func (_m *Parser) Parse(ctx context.Context, _a1 *artifact.Artifact, manifest []byte) error {
ret := _m.Called(ctx, _a1, manifest) ret := _m.Called(ctx, _a1, manifest)
if len(ret) == 0 {
panic("no return value specified for Parse")
}
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, []byte) error); ok { if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, []byte) error); ok {
r0 = rf(ctx, _a1, manifest) r0 = rf(ctx, _a1, manifest)
@ -28,3 +32,17 @@ func (_m *Parser) Parse(ctx context.Context, _a1 *artifact.Artifact, manifest []
return r0 return r0
} }
// NewParser creates a new instance of Parser. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewParser(t interface {
mock.TestingT
Cleanup(func())
}) *Parser {
mock := &Parser{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,14 +1,15 @@
// Code generated by mockery v2.1.0. DO NOT EDIT. // Code generated by mockery v2.43.2. DO NOT EDIT.
package processor package processor
import ( import (
context "context" context "context"
artifact "github.com/goharbor/harbor/src/pkg/artifact"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
processor "github.com/goharbor/harbor/src/controller/artifact/processor" processor "github.com/goharbor/harbor/src/controller/artifact/processor"
artifact "github.com/goharbor/harbor/src/pkg/artifact"
) )
// Processor is an autogenerated mock type for the Processor type // Processor is an autogenerated mock type for the Processor type
@ -20,7 +21,15 @@ type Processor struct {
func (_m *Processor) AbstractAddition(ctx context.Context, _a1 *artifact.Artifact, additionType string) (*processor.Addition, error) { func (_m *Processor) AbstractAddition(ctx context.Context, _a1 *artifact.Artifact, additionType string) (*processor.Addition, error) {
ret := _m.Called(ctx, _a1, additionType) ret := _m.Called(ctx, _a1, additionType)
if len(ret) == 0 {
panic("no return value specified for AbstractAddition")
}
var r0 *processor.Addition var r0 *processor.Addition
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, string) (*processor.Addition, error)); ok {
return rf(ctx, _a1, additionType)
}
if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, string) *processor.Addition); ok { if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, string) *processor.Addition); ok {
r0 = rf(ctx, _a1, additionType) r0 = rf(ctx, _a1, additionType)
} else { } else {
@ -29,7 +38,6 @@ func (_m *Processor) AbstractAddition(ctx context.Context, _a1 *artifact.Artifac
} }
} }
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *artifact.Artifact, string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *artifact.Artifact, string) error); ok {
r1 = rf(ctx, _a1, additionType) r1 = rf(ctx, _a1, additionType)
} else { } else {
@ -43,6 +51,10 @@ func (_m *Processor) AbstractAddition(ctx context.Context, _a1 *artifact.Artifac
func (_m *Processor) AbstractMetadata(ctx context.Context, _a1 *artifact.Artifact, manifest []byte) error { func (_m *Processor) AbstractMetadata(ctx context.Context, _a1 *artifact.Artifact, manifest []byte) error {
ret := _m.Called(ctx, _a1, manifest) ret := _m.Called(ctx, _a1, manifest)
if len(ret) == 0 {
panic("no return value specified for AbstractMetadata")
}
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, []byte) error); ok { if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact, []byte) error); ok {
r0 = rf(ctx, _a1, manifest) r0 = rf(ctx, _a1, manifest)
@ -57,6 +69,10 @@ func (_m *Processor) AbstractMetadata(ctx context.Context, _a1 *artifact.Artifac
func (_m *Processor) GetArtifactType(ctx context.Context, _a1 *artifact.Artifact) string { func (_m *Processor) GetArtifactType(ctx context.Context, _a1 *artifact.Artifact) string {
ret := _m.Called(ctx, _a1) ret := _m.Called(ctx, _a1)
if len(ret) == 0 {
panic("no return value specified for GetArtifactType")
}
var r0 string var r0 string
if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact) string); ok { if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact) string); ok {
r0 = rf(ctx, _a1) r0 = rf(ctx, _a1)
@ -71,6 +87,10 @@ func (_m *Processor) GetArtifactType(ctx context.Context, _a1 *artifact.Artifact
func (_m *Processor) ListAdditionTypes(ctx context.Context, _a1 *artifact.Artifact) []string { func (_m *Processor) ListAdditionTypes(ctx context.Context, _a1 *artifact.Artifact) []string {
ret := _m.Called(ctx, _a1) ret := _m.Called(ctx, _a1)
if len(ret) == 0 {
panic("no return value specified for ListAdditionTypes")
}
var r0 []string var r0 []string
if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact) []string); ok { if rf, ok := ret.Get(0).(func(context.Context, *artifact.Artifact) []string); ok {
r0 = rf(ctx, _a1) r0 = rf(ctx, _a1)
@ -82,3 +102,17 @@ func (_m *Processor) ListAdditionTypes(ctx context.Context, _a1 *artifact.Artifa
return r0 return r0
} }
// NewProcessor creates a new instance of Processor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewProcessor(t interface {
mock.TestingT
Cleanup(func())
}) *Processor {
mock := &Processor{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,256 +0,0 @@
// Code generated by mockery v2.1.0. DO NOT EDIT.
package scan
import (
context "context"
mock "github.com/stretchr/testify/mock"
q "github.com/goharbor/harbor/src/lib/q"
scan "github.com/goharbor/harbor/src/pkg/scan/dao/scan"
)
// VulnerabilityRecordDao is an autogenerated mock type for the VulnerabilityRecordDao type
type VulnerabilityRecordDao struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, vr
func (_m *VulnerabilityRecordDao) Create(ctx context.Context, vr *scan.VulnerabilityRecord) (int64, error) {
ret := _m.Called(ctx, vr)
var r0 int64
if rf, ok := ret.Get(0).(func(context.Context, *scan.VulnerabilityRecord) int64); ok {
r0 = rf(ctx, vr)
} else {
r0 = ret.Get(0).(int64)
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *scan.VulnerabilityRecord) error); ok {
r1 = rf(ctx, vr)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: ctx, vr
func (_m *VulnerabilityRecordDao) Delete(ctx context.Context, vr *scan.VulnerabilityRecord) error {
ret := _m.Called(ctx, vr)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *scan.VulnerabilityRecord) error); ok {
r0 = rf(ctx, vr)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteForDigests provides a mock function with given fields: ctx, digests
func (_m *VulnerabilityRecordDao) DeleteForDigests(ctx context.Context, digests ...string) (int64, error) {
_va := make([]interface{}, len(digests))
for _i := range digests {
_va[_i] = digests[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 int64
if rf, ok := ret.Get(0).(func(context.Context, ...string) int64); ok {
r0 = rf(ctx, digests...)
} else {
r0 = ret.Get(0).(int64)
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, ...string) error); ok {
r1 = rf(ctx, digests...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// DeleteForReport provides a mock function with given fields: ctx, reportUUID
func (_m *VulnerabilityRecordDao) DeleteForReport(ctx context.Context, reportUUID string) (int64, error) {
ret := _m.Called(ctx, reportUUID)
var r0 int64
if rf, ok := ret.Get(0).(func(context.Context, string) int64); ok {
r0 = rf(ctx, reportUUID)
} else {
r0 = ret.Get(0).(int64)
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, reportUUID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// DeleteForScanner provides a mock function with given fields: ctx, registrationUUID
func (_m *VulnerabilityRecordDao) DeleteForScanner(ctx context.Context, registrationUUID string) (int64, error) {
ret := _m.Called(ctx, registrationUUID)
var r0 int64
if rf, ok := ret.Get(0).(func(context.Context, string) int64); ok {
r0 = rf(ctx, registrationUUID)
} else {
r0 = ret.Get(0).(int64)
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, registrationUUID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetForReport provides a mock function with given fields: ctx, reportUUID
func (_m *VulnerabilityRecordDao) GetForReport(ctx context.Context, reportUUID string) ([]*scan.VulnerabilityRecord, error) {
ret := _m.Called(ctx, reportUUID)
var r0 []*scan.VulnerabilityRecord
if rf, ok := ret.Get(0).(func(context.Context, string) []*scan.VulnerabilityRecord); ok {
r0 = rf(ctx, reportUUID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*scan.VulnerabilityRecord)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, reportUUID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetForScanner provides a mock function with given fields: ctx, registrationUUID
func (_m *VulnerabilityRecordDao) GetForScanner(ctx context.Context, registrationUUID string) ([]*scan.VulnerabilityRecord, error) {
ret := _m.Called(ctx, registrationUUID)
var r0 []*scan.VulnerabilityRecord
if rf, ok := ret.Get(0).(func(context.Context, string) []*scan.VulnerabilityRecord); ok {
r0 = rf(ctx, registrationUUID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*scan.VulnerabilityRecord)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, registrationUUID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetRecordIdsForScanner provides a mock function with given fields: ctx, registrationUUID
func (_m *VulnerabilityRecordDao) GetRecordIdsForScanner(ctx context.Context, registrationUUID string) ([]int, error) {
ret := _m.Called(ctx, registrationUUID)
var r0 []int
if rf, ok := ret.Get(0).(func(context.Context, string) []int); ok {
r0 = rf(ctx, registrationUUID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]int)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, registrationUUID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// InsertForReport provides a mock function with given fields: ctx, reportUUID, vulnerabilityRecordIDs
func (_m *VulnerabilityRecordDao) InsertForReport(ctx context.Context, reportUUID string, vulnerabilityRecordIDs ...int64) error {
_va := make([]interface{}, len(vulnerabilityRecordIDs))
for _i := range vulnerabilityRecordIDs {
_va[_i] = vulnerabilityRecordIDs[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, reportUUID)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, ...int64) error); ok {
r0 = rf(ctx, reportUUID, vulnerabilityRecordIDs...)
} else {
r0 = ret.Error(0)
}
return r0
}
// List provides a mock function with given fields: ctx, query
func (_m *VulnerabilityRecordDao) List(ctx context.Context, query *q.Query) ([]*scan.VulnerabilityRecord, error) {
ret := _m.Called(ctx, query)
var r0 []*scan.VulnerabilityRecord
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) []*scan.VulnerabilityRecord); ok {
r0 = rf(ctx, query)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*scan.VulnerabilityRecord)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, vr, cols
func (_m *VulnerabilityRecordDao) Update(ctx context.Context, vr *scan.VulnerabilityRecord, cols ...string) error {
_va := make([]interface{}, len(cols))
for _i := range cols {
_va[_i] = cols[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, vr)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *scan.VulnerabilityRecord, ...string) error); ok {
r0 = rf(ctx, vr, cols...)
} else {
r0 = ret.Error(0)
}
return r0
}

View File

@ -0,0 +1,91 @@
// Code generated by mockery v2.43.2. DO NOT EDIT.
package postprocessors
import (
context "context"
mock "github.com/stretchr/testify/mock"
)
// NativeScanReportConverter is an autogenerated mock type for the NativeScanReportConverter type
type NativeScanReportConverter struct {
mock.Mock
}
// FromRelationalSchema provides a mock function with given fields: ctx, reportUUID, artifactDigest, reportSummary
func (_m *NativeScanReportConverter) FromRelationalSchema(ctx context.Context, reportUUID string, artifactDigest string, reportSummary string) (string, error) {
ret := _m.Called(ctx, reportUUID, artifactDigest, reportSummary)
if len(ret) == 0 {
panic("no return value specified for FromRelationalSchema")
}
var r0 string
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (string, error)); ok {
return rf(ctx, reportUUID, artifactDigest, reportSummary)
}
if rf, ok := ret.Get(0).(func(context.Context, string, string, string) string); ok {
r0 = rf(ctx, reportUUID, artifactDigest, reportSummary)
} else {
r0 = ret.Get(0).(string)
}
if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok {
r1 = rf(ctx, reportUUID, artifactDigest, reportSummary)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ToRelationalSchema provides a mock function with given fields: ctx, reportUUID, registrationUUID, digest, reportData
func (_m *NativeScanReportConverter) ToRelationalSchema(ctx context.Context, reportUUID string, registrationUUID string, digest string, reportData string) (string, string, error) {
ret := _m.Called(ctx, reportUUID, registrationUUID, digest, reportData)
if len(ret) == 0 {
panic("no return value specified for ToRelationalSchema")
}
var r0 string
var r1 string
var r2 error
if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) (string, string, error)); ok {
return rf(ctx, reportUUID, registrationUUID, digest, reportData)
}
if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) string); ok {
r0 = rf(ctx, reportUUID, registrationUUID, digest, reportData)
} else {
r0 = ret.Get(0).(string)
}
if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string) string); ok {
r1 = rf(ctx, reportUUID, registrationUUID, digest, reportData)
} else {
r1 = ret.Get(1).(string)
}
if rf, ok := ret.Get(2).(func(context.Context, string, string, string, string) error); ok {
r2 = rf(ctx, reportUUID, registrationUUID, digest, reportData)
} else {
r2 = ret.Error(2)
}
return r0, r1, r2
}
// NewNativeScanReportConverter creates a new instance of NativeScanReportConverter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewNativeScanReportConverter(t interface {
mock.TestingT
Cleanup(func())
}) *NativeScanReportConverter {
mock := &NativeScanReportConverter{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,23 +0,0 @@
package postprocessors
import (
"context"
mock "github.com/stretchr/testify/mock"
)
// ScanReportV1ToV2Converter is an auto-generated mock type for converting native Harbor report in JSON
// to relational schema
type ScanReportV1ToV2Converter struct {
mock.Mock
}
// ToRelationalSchema is a mock implementation of the scan report conversion
func (_c *ScanReportV1ToV2Converter) ToRelationalSchema(ctx context.Context, reportUUID string, registrationUUID string, digest string, reportData string) (string, string, error) {
return "mockId", reportData, nil
}
// ToRelationalSchema is a mock implementation of the scan report conversion
func (_c *ScanReportV1ToV2Converter) FromRelationalSchema(ctx context.Context, reportUUID string, artifactDigest string, reportData string) (string, error) {
return "mockId", nil
}

View File

@ -1,79 +1,208 @@
// Copyright Project Harbor Authors // Code generated by mockery v2.43.2. DO NOT EDIT.
//
// 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 tag package tag
import ( import (
"context" context "context"
"github.com/stretchr/testify/mock" modeltag "github.com/goharbor/harbor/src/pkg/tag/model/tag"
mock "github.com/stretchr/testify/mock"
"github.com/goharbor/harbor/src/lib/q" q "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/tag/model/tag"
) )
// FakeManager is a fake tag manager that implement the src/pkg/tag.Manager interface // Manager is an autogenerated mock type for the Manager type
type FakeManager struct { type Manager struct {
mock.Mock mock.Mock
} }
// Count ... // Count provides a mock function with given fields: ctx, query
func (f *FakeManager) Count(ctx context.Context, query *q.Query) (int64, error) { func (_m *Manager) Count(ctx context.Context, query *q.Query) (int64, error) {
args := f.Called() ret := _m.Called(ctx, query)
return int64(args.Int(0)), args.Error(1)
}
// List ... if len(ret) == 0 {
func (f *FakeManager) List(ctx context.Context, query *q.Query) ([]*tag.Tag, error) { panic("no return value specified for Count")
args := f.Called()
var tags []*tag.Tag
if args.Get(0) != nil {
tags = args.Get(0).([]*tag.Tag)
} }
return tags, args.Error(1)
}
// Get ... var r0 int64
func (f *FakeManager) Get(ctx context.Context, id int64) (*tag.Tag, error) { var r1 error
args := f.Called() if rf, ok := ret.Get(0).(func(context.Context, *q.Query) (int64, error)); ok {
var tg *tag.Tag return rf(ctx, query)
if args.Get(0) != nil {
tg = args.Get(0).(*tag.Tag)
} }
return tg, args.Error(1) if rf, ok := ret.Get(0).(func(context.Context, *q.Query) int64); ok {
r0 = rf(ctx, query)
} else {
r0 = ret.Get(0).(int64)
}
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query)
} else {
r1 = ret.Error(1)
}
return r0, r1
} }
// Create ... // Create provides a mock function with given fields: ctx, _a1
func (f *FakeManager) Create(ctx context.Context, tag *tag.Tag) (int64, error) { func (_m *Manager) Create(ctx context.Context, _a1 *modeltag.Tag) (int64, error) {
args := f.Called() ret := _m.Called(ctx, _a1)
return int64(args.Int(0)), args.Error(1)
if len(ret) == 0 {
panic("no return value specified for Create")
}
var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *modeltag.Tag) (int64, error)); ok {
return rf(ctx, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *modeltag.Tag) int64); ok {
r0 = rf(ctx, _a1)
} else {
r0 = ret.Get(0).(int64)
}
if rf, ok := ret.Get(1).(func(context.Context, *modeltag.Tag) error); ok {
r1 = rf(ctx, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
} }
// Update ... // Delete provides a mock function with given fields: ctx, id
func (f *FakeManager) Update(ctx context.Context, tag *tag.Tag, props ...string) error { func (_m *Manager) Delete(ctx context.Context, id int64) error {
args := f.Called() ret := _m.Called(ctx, id)
return args.Error(0)
if len(ret) == 0 {
panic("no return value specified for Delete")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
r0 = rf(ctx, id)
} else {
r0 = ret.Error(0)
}
return r0
} }
// Delete ... // DeleteOfArtifact provides a mock function with given fields: ctx, artifactID
func (f *FakeManager) Delete(ctx context.Context, id int64) error { func (_m *Manager) DeleteOfArtifact(ctx context.Context, artifactID int64) error {
args := f.Called() ret := _m.Called(ctx, artifactID)
return args.Error(0)
if len(ret) == 0 {
panic("no return value specified for DeleteOfArtifact")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
r0 = rf(ctx, artifactID)
} else {
r0 = ret.Error(0)
}
return r0
} }
// DeleteOfArtifact ... // Get provides a mock function with given fields: ctx, id
func (f *FakeManager) DeleteOfArtifact(ctx context.Context, artifactID int64) error { func (_m *Manager) Get(ctx context.Context, id int64) (*modeltag.Tag, error) {
args := f.Called() ret := _m.Called(ctx, id)
return args.Error(0)
if len(ret) == 0 {
panic("no return value specified for Get")
}
var r0 *modeltag.Tag
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int64) (*modeltag.Tag, error)); ok {
return rf(ctx, id)
}
if rf, ok := ret.Get(0).(func(context.Context, int64) *modeltag.Tag); ok {
r0 = rf(ctx, id)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*modeltag.Tag)
}
}
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
r1 = rf(ctx, id)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// List provides a mock function with given fields: ctx, query
func (_m *Manager) List(ctx context.Context, query *q.Query) ([]*modeltag.Tag, error) {
ret := _m.Called(ctx, query)
if len(ret) == 0 {
panic("no return value specified for List")
}
var r0 []*modeltag.Tag
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) ([]*modeltag.Tag, error)); ok {
return rf(ctx, query)
}
if rf, ok := ret.Get(0).(func(context.Context, *q.Query) []*modeltag.Tag); ok {
r0 = rf(ctx, query)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*modeltag.Tag)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *q.Query) error); ok {
r1 = rf(ctx, query)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, _a1, props
func (_m *Manager) Update(ctx context.Context, _a1 *modeltag.Tag, props ...string) error {
_va := make([]interface{}, len(props))
for _i := range props {
_va[_i] = props[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, _a1)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for Update")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *modeltag.Tag, ...string) error); ok {
r0 = rf(ctx, _a1, props...)
} else {
r0 = ret.Error(0)
}
return r0
}
// NewManager creates a new instance of Manager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewManager(t interface {
mock.TestingT
Cleanup(func())
}) *Manager {
mock := &Manager{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
} }

View File

@ -1,24 +1,78 @@
// Code generated by mockery v2.43.2. DO NOT EDIT.
package registryctl package registryctl
import ( import mock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
)
type Mockclient struct { // Client is an autogenerated mock type for the Client type
type Client struct {
mock.Mock mock.Mock
} }
// Health ... // DeleteBlob provides a mock function with given fields: reference
func (c *Mockclient) Health() error { func (_m *Client) DeleteBlob(reference string) error {
return nil ret := _m.Called(reference)
if len(ret) == 0 {
panic("no return value specified for DeleteBlob")
}
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(reference)
} else {
r0 = ret.Error(0)
}
return r0
} }
// DeleteBlob ... // DeleteManifest provides a mock function with given fields: repository, reference
func (c *Mockclient) DeleteBlob(reference string) (err error) { func (_m *Client) DeleteManifest(repository string, reference string) error {
return nil ret := _m.Called(repository, reference)
if len(ret) == 0 {
panic("no return value specified for DeleteManifest")
}
var r0 error
if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(repository, reference)
} else {
r0 = ret.Error(0)
}
return r0
} }
// DeleteManifest ... // Health provides a mock function with given fields:
func (c *Mockclient) DeleteManifest(repository, reference string) (err error) { func (_m *Client) Health() error {
return nil ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Health")
}
var r0 error
if rf, ok := ret.Get(0).(func() error); ok {
r0 = rf()
} else {
r0 = ret.Error(0)
}
return r0
}
// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewClient(t interface {
mock.TestingT
Cleanup(func())
}) *Client {
mock := &Client{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
} }