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 (v2) #2839

Merged
merged 7 commits into from
Feb 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
go:
- version: 1.21.x
- version: 1.22.x
may-fail: false
- version: tip
may-fail: true
Expand Down
132 changes: 132 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# This is the top-level configuration file for mockery.
disable-version-string: True
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/dbaas/kubernetes/client:
interfaces:
KubeClientConnector:
config:
mockname: "Mock{{ .InterfaceName | camelcase }}"
filename: "mock_{{ .InterfaceName | snakecase }}.go"
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/dbaas:
interfaces:
dbaasClient:
versionService:
grafanaClient:
componentsService:
kubernetesClient:
kubeStorageManager:
github.com/percona/pmm/managed/services/management/dump:
interfaces:
dumpService:
github.com/percona/pmm/managed/services/management/ia:
interfaces:
alertManager:
vmAlert:
templatesService:
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 }}"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Dockerfile is used only for API tests.

FROM golang:1.21
FROM golang:1.22

RUN export GOPATH=$(go env GOPATH) && \
mkdir -p $GOPATH/src/github.com/percona/pmm
Expand Down
6 changes: 6 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,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
4 changes: 2 additions & 2 deletions build/docker/rpmbuild/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ RUN yum update -y && \
yum clean all && rm -rf /var/cache/yum

# keep that format for easier search
ENV GO_VERSION 1.21.3
ENV GO_RELEASER_VERSION 1.21.2
ENV GO_VERSION 1.22.0
ENV GO_RELEASER_VERSION 1.24.0

RUN if [ `uname -i` == "x86_64" ]; then ARCH=amd64; else ARCH=arm64; fi && \
wget --progress=dot:giga https://dl.google.com/go/go${GO_VERSION}.linux-${ARCH}.tar.gz -O /tmp/golang.tar.gz && \
Expand Down
4 changes: 2 additions & 2 deletions build/docker/rpmbuild/Dockerfile.el9
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ RUN yum update -y && \
yum clean all && rm -rf /var/cache/yum

# keep that format for easier search
ENV GO_VERSION 1.21.3
ENV GO_RELEASER_VERSION 1.21.2
ENV GO_VERSION 1.22.0
ENV GO_RELEASER_VERSION 1.24.0

RUN if [ `uname -i` == "x86_64" ]; then ARCH=amd64; else ARCH=arm64; fi && \
wget --progress=dot:giga https://dl.google.com/go/go${GO_VERSION}.linux-${ARCH}.tar.gz -O /tmp/golang.tar.gz && \
Expand Down
2 changes: 1 addition & 1 deletion devcontainer.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG PMM_SERVER_IMAGE="perconalab/pmm-server:dev-latest"
FROM $PMM_SERVER_IMAGE

ARG PMM_SERVER_IMAGE
ARG GO_VERSION="1.21.x"
ARG GO_VERSION="1.22.x"

RUN echo "Building with: GO: $GO_VERSION, PMM: $PMM_SERVER_IMAGE"
ENV GOPATH=/root/go
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/percona/pmm

go 1.21
go 1.22

toolchain go1.22.0

// Update saas with
// go get -v github.com/percona-platform/saas@latest
Expand Down
1 change: 0 additions & 1 deletion managed/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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.

1 change: 0 additions & 1 deletion managed/services/dbaas/kubernetes/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
package client

//go:generate ../../../../../bin/ifacemaker -f client.go -s Client -i KubeClientConnector -p client -o kubeclient_interface.go
//go:generate ../../../../../bin/mockery --name=KubeClientConnector --case=snake --inpackage

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

Loading
Loading