Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-12429 Use a configuration file for mockery #2621

Merged
merged 9 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# This is the top-level configuration file for mockery.
disable-version-string: True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥👍

with-expecter: False
inpackage: True
dir: "{{.InterfaceDir}}"
filename: "mock_{{ .InterfaceName | snakecase }}_test.go"
mockname: "mock{{ .InterfaceName | camelcase }}"
packages:
# managed
github.com/percona/pmm/managed/services/backup:
interfaces:
agentService:
compatibilityService:
jobsService:
pbmPITRService:
removalService:
Storage:
config:
mockname: "Mock{{ .InterfaceName | camelcase }}"
versioner:
github.com/percona/pmm/managed/services/checks:
interfaces:
agentsRegistry:
github.com/percona/pmm/managed/services/grafana:
interfaces:
awsInstanceChecker:
github.com/percona/pmm/managed/services/inventory:
interfaces:
agentService:
agentsRegistry:
agentsStateUpdater:
connectionChecker:
inventoryMetrics:
prometheusService:
serviceInfoBroker:
versionCache:
github.com/percona/pmm/managed/services/management:
interfaces:
agentsRegistry:
agentsStateUpdater:
apiKeyProvider:
checksService:
connectionChecker:
grafanaClient:
jobsService:
prometheusService:
serviceInfoBroker:
versionCache:
victoriaMetricsClient:
github.com/percona/pmm/managed/services/management/alerting:
interfaces:
grafanaClient:
github.com/percona/pmm/managed/services/management/backup:
interfaces:
awsS3:
backupService:
scheduleService:
removalService:
pbmPITRService:
github.com/percona/pmm/managed/services/qan:
interfaces:
qanCollectorClient:
github.com/percona/pmm/managed/services/scheduler:
interfaces:
backupService:
github.com/percona/pmm/managed/services/server:
interfaces:
agentsStateUpdater:
alertmanagerService:
checksService:
emailer:
grafanaClient:
prometheusService:
rulesService:
supervisordService:
telemetryService:
templatesService:
vmAlertExternalRules:
github.com/percona/pmm/managed/services/versioncache:
interfaces:
Versioner:
config:
mockname: "Mock{{ .InterfaceName | camelcase }}"
github.com/percona/pmm/managed/services/telemetry:
interfaces:
DataSource:
DataSourceLocator:
distributionUtilService:
sender:
# admin
github.com/percona/pmm/admin/commands/pmm/server/docker:
interfaces:
Functions:
config:
mockname: "Mock{{ .InterfaceName | camelcase }}"
# agent
github.com/percona/pmm/agent/agentlocal:
interfaces:
client:
supervisor:
github.com/percona/pmm/agent/client:
interfaces:
connectionChecker:
serviceInfoBroker:
supervisor:
github.com/percona/pmm/agent/versioner:
interfaces:
ExecFunctions:
config:
mockname: "Mock{{ .InterfaceName | camelcase }}"
6 changes: 6 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ gen: clean ## Generate files
make -C admin gen
make -C managed gen

make gen-mocks ## Generate mocks

make format
make format ## TODO: One formatting run is not enough, figure out why.
go install -v ./...

gen-mocks:
find . -name mock_*.go -delete
./bin/mockery --config .mockery.yaml

gen-api: ## Generate PMM API
# generated by descriptors target
bin/buf breaking --against descriptor.bin api
Expand Down
1 change: 0 additions & 1 deletion admin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ gen: clean ## Generate files

clean: ## Remove generated files
find . -name *_reform.go -delete
find . -name mock_*.go -delete

release: ## Build pmm-admin release binary
env CGO_ENABLED=0 go build -v $(LD_FLAGS) -o $(PMM_RELEASE_PATH)/pmm-admin ./cmd/pmm-admin/
Expand Down
2 changes: 0 additions & 2 deletions admin/commands/pmm/server/docker/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"github.com/percona/pmm/admin/pkg/docker"
)

//go:generate ../../../../../bin/mockery --name=Functions --case=snake --inpackage --testonly

// Functions contain methods required to interact with Docker.
type Functions interface { //nolint:interfacebloat
Imager
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/pmm/server/docker/mock_functions_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ gen: clean ## Generate files

clean: ## Remove generated files
find . -name *_reform.go -delete
find . -name mock_*.go -delete

# generate stub models for perfschema QAN agent; hidden from help as it is not generally useful
gen-init:
Expand Down
3 changes: 0 additions & 3 deletions agent/agentlocal/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (
"github.com/percona/pmm/api/agentpb"
)

//go:generate ../../bin/mockery --name=client --case=snake --inpackage --testonly
//go:generate ../../bin/mockery --name=supervisor --case=snake --inpackage --testonly

// client is a subset of methods of client.Client used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type client interface {
Expand Down
2 changes: 1 addition & 1 deletion agent/agentlocal/mock_client_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/agentlocal/mock_supervisor_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions agent/client/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (
"github.com/percona/pmm/api/agentpb"
)

//go:generate ../../bin/mockery --name=connectionChecker --case=snake --inpackage --testonly
//go:generate ../../bin/mockery --name=serviceInfoBroker --case=snake --inpackage --testonly
//go:generate ../../bin/mockery --name=supervisor --case=snake --inpackage --testonly

// connectionChecker is a subset of methods of connectionchecker.ConnectionChecker used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type connectionChecker interface {
Expand Down
2 changes: 1 addition & 1 deletion agent/client/mock_connection_checker_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/client/mock_service_info_broker_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/client/mock_supervisor_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/versioner/mock_exec_functions_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions agent/versioner/versioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type CombinedOutputer interface {
CombinedOutput() ([]byte, error)
}

//go:generate ../../bin/mockery --name=ExecFunctions --case=snake --inpackage --testonly

// ExecFunctions is an interface for the LookPath() and CommandContext() functions.
type ExecFunctions interface {
LookPath(file string) (string, error)
Expand Down
1 change: 0 additions & 1 deletion managed/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ gen: clean ## Generate files

clean: ## Remove generated files
find . -name *_reform.go -delete
find . -name mock_*.go -delete

release: ## Build pmm-managed release binaries
env CGO_ENABLED=0 go build -v $(PMM_LD_FLAGS) -o $(PMM_RELEASE_PATH)/ ./cmd/...
Expand Down
8 changes: 0 additions & 8 deletions managed/services/backup/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ import (
"github.com/percona/pmm/managed/services/minio"
)

//go:generate ../../../bin/mockery --name=jobsService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=agentService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=versioner --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=compatibilityService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=pbmPITRService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=Storage --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=removalService --case=snake --inpackage --testonly

// jobsService is a subset of methods of agents.JobsService used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type jobsService interface {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/backup/mock_agent_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/backup/mock_jobs_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/backup/mock_pbm_pitr_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/backup/mock_removal_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/backup/mock_storage_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/backup/mock_versioner_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions managed/services/checks/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/percona/pmm/managed/models"
)

//go:generate ../../../bin/mockery --name=agentsRegistry --case=snake --inpackage --testonly

// agentsRegistry is a subset of methods of agents.Registry used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type agentsRegistry interface {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/checks/mock_agents_registry_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions managed/services/grafana/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package grafana

//go:generate ../../../bin/mockery --name=awsInstanceChecker --case=snake --inpackage --testonly

// checker is a subset of methods of server.AWSInstanceChecker used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type awsInstanceChecker interface {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions managed/services/inventory/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ import (
"github.com/percona/pmm/managed/models"
)

//go:generate ../../../bin/mockery --name=agentsRegistry --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=agentService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=agentsStateUpdater --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=prometheusService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=connectionChecker --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=serviceInfoBroker --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=versionCache --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=inventoryMetrics --case=snake --inpackage --testonly

// agentsRegistry is a subset of methods of agents.Registry used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type agentsRegistry interface {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/inventory/mock_agent_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/inventory/mock_agents_registry_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion managed/services/inventory/mock_version_cache_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions managed/services/management/alerting/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/percona/pmm/managed/services"
)

//go:generate ../../../../bin/mockery --name=grafanaClient --case=snake --inpackage --testonly

type grafanaClient interface {
CreateAlertRule(ctx context.Context, folderName, groupName string, rule *services.Rule) error
GetDatasourceUIDByID(ctx context.Context, id int64) (string, error)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading