Skip to content

Commit

Permalink
refactor: unify the mock file generation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chlins committed Jul 25, 2024
1 parent 64df11b commit c74c3a1
Show file tree
Hide file tree
Showing 18 changed files with 870 additions and 607 deletions.
80 changes: 62 additions & 18 deletions src/.mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ packages:
Controller:
config:
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
github.com/goharbor/harbor/src/controller/blob:
interfaces:
Controller:
Expand Down Expand Up @@ -188,6 +198,11 @@ packages:
Manager:
config:
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:
interfaces:
Manager:
Expand Down Expand Up @@ -218,6 +233,11 @@ packages:
Handler:
config:
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:
interfaces:
Manager:
Expand All @@ -238,7 +258,7 @@ packages:
dir: pkg/scheduler
outpkg: scheduler
mockname: mockDAO
filename: mock_dao_test.go
filename: mock_dao_test.go
inpackage: True
Scheduler:
config:
Expand Down Expand Up @@ -342,6 +362,14 @@ packages:
DAO:
config:
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:
interfaces:
Manager:
Expand Down Expand Up @@ -505,20 +533,36 @@ packages:
Manager:
config:
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
4 changes: 2 additions & 2 deletions src/controller/artifact/processor/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ type processorTestSuite struct {
suite.Suite
processor *processor
regCli *registry.Client
chartOptr *chart.FakeOpertaor
chartOptr *chart.Operator
}

func (p *processorTestSuite) SetupTest() {
p.regCli = &registry.Client{}
p.chartOptr = &chart.FakeOpertaor{}
p.chartOptr = &chart.Operator{}
p.processor = &processor{
chartOperator: p.chartOptr,
}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/tag/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ type controllerTestSuite struct {
ctl *controller
repoMgr *repository.Manager
artMgr *artifact.Manager
tagMgr *tagtesting.FakeManager
tagMgr *tagtesting.Manager
immutableMtr *immutable.FakeMatcher
}

func (c *controllerTestSuite) SetupTest() {
c.repoMgr = &repository.Manager{}
c.artMgr = &artifact.Manager{}
c.tagMgr = &tagtesting.FakeManager{}
c.tagMgr = &tagtesting.Manager{}
c.immutableMtr = &immutable.FakeMatcher{}
c.ctl = &controller{
tagMgr: c.tagMgr,
Expand Down
8 changes: 4 additions & 4 deletions src/jobservice/job/impl/gc/garbage_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import (
type gcTestSuite struct {
htesting.Suite
artifactCtl *artifacttesting.Controller
artrashMgr *trashtesting.FakeManager
registryCtlClient *registryctl.Mockclient
artrashMgr *trashtesting.Manager
registryCtlClient *registryctl.Client
projectCtl *projecttesting.Controller
blobMgr *blob.Manager

Expand All @@ -54,8 +54,8 @@ type gcTestSuite struct {

func (suite *gcTestSuite) SetupTest() {
suite.artifactCtl = &artifacttesting.Controller{}
suite.artrashMgr = &trashtesting.FakeManager{}
suite.registryCtlClient = &registryctl.Mockclient{}
suite.artrashMgr = &trashtesting.Manager{}
suite.registryCtlClient = &registryctl.Client{}
suite.blobMgr = &blob.Manager{}
suite.projectCtl = &projecttesting.Controller{}

Expand Down
136 changes: 0 additions & 136 deletions src/testing/lib/libcache/cache.go

This file was deleted.

Loading

0 comments on commit c74c3a1

Please sign in to comment.