Skip to content

Commit 9628218

Browse files
authored
CLOUDP-62054: replace mock generation in make with go generate (#187)
1 parent 8481b43 commit 9628218

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+550
-1263
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ We provide a git pre-commit hook to format and check the code, to install it run
4848

4949
### Generating Mocks
5050

51-
We use [mockgen](https://github.com/golang/mock) to handle mocking in our unit tests
52-
If you need a new mock please add a reference on the [Make](Makefile) file and run `make gen-mocks`
51+
We use [mockgen](https://github.com/golang/mock) to handle mocking in our unit tests.
52+
If you need a new mock please update or add the `//go:generate` instruction to the appropriate file
5353

5454
### Adding a New Command
5555

Makefile

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,7 @@ addlicense:
5656
.PHONY: gen-mocks
5757
gen-mocks: ## Generate mocks
5858
@echo "==> Generating mocks"
59-
mockgen -source=internal/config/profile.go -destination=internal/mocks/mock_profile.go -package=mocks
60-
mockgen -source=internal/store/alert_configuration.go -destination=internal/mocks/mock_alert_configuration.go -package=mocks
61-
mockgen -source=internal/store/automation.go -destination=internal/mocks/mock_automation.go -package=mocks
62-
mockgen -source=internal/store/clusters.go -destination=internal/mocks/mock_clusters.go -package=mocks
63-
mockgen -source=internal/store/database_users.go -destination=internal/mocks/mock_database_users.go -package=mocks
64-
mockgen -source=internal/store/project_ip_whitelist.go -destination=internal/mocks/mock_project_ip_whitelist.go -package=mocks
65-
mockgen -source=internal/store/projects.go -destination=internal/mocks/mock_projects.go -package=mocks
66-
mockgen -source=internal/store/organizations.go -destination=internal/mocks/mock_organizations.go -package=mocks
67-
mockgen -source=internal/store/owners.go -destination=internal/mocks/mock_owners.go -package=mocks
68-
mockgen -source=internal/store/continuous_snapshots.go -destination=internal/mocks/mock_continuous_snapshots.go -package=mocks
69-
mockgen -source=internal/store/continuous_jobs.go -destination=internal/mocks/mock_continuous_jobs.go -package=mocks
70-
mockgen -source=internal/store/agents.go -destination=internal/mocks/mock_agents.go -package=mocks
71-
mockgen -source=internal/store/checkpoints.go -destination=internal/mocks/mock_checkpoints.go -package=mocks
72-
mockgen -source=internal/store/alerts.go -destination=internal/mocks/mock_alerts.go -package=mocks
73-
mockgen -source=internal/store/global_alerts.go -destination=internal/mocks/mock_global_alerts.go -package=mocks
74-
mockgen -source=internal/store/events.go -destination=internal/mocks/mock_events.go -package=mocks
75-
mockgen -source=internal/store/process_measurements.go -destination=internal/mocks/mock_process_measurements.go -package=mocks
76-
mockgen -source=internal/store/process_disks.go -destination=internal/mocks/mock_process_disks.go -package=mocks
77-
mockgen -source=internal/store/process_disk_measurements.go -destination=internal/mocks/mock_process_disk_measurements.go -package=mocks
78-
mockgen -source=internal/store/process_databases.go -destination=internal/mocks/mock_process_databases.go -package=mocks
79-
mockgen -source=internal/store/host_measurements.go -destination=internal/mocks/mock_host_measurements.go -package=mocks
80-
mockgen -source=internal/store/indexes.go -destination=internal/mocks/mock_indexes.go -package=mocks
81-
mockgen -source=internal/store/processes.go -destination=internal/mocks/mock_processes.go -package=mocks
82-
mockgen -source=internal/store/logs.go -destination=internal/mocks/mock_logs.go -package=mocks
83-
mockgen -source=internal/store/hosts.go -destination=internal/mocks/mock_hosts.go -package=mocks
84-
mockgen -source=internal/store/host_databases.go -destination=internal/mocks/mock_host_databases.go -package=mocks
85-
mockgen -source=internal/store/host_disks.go -destination=internal/mocks/mock_host_disks.go -package=mocks
86-
mockgen -source=internal/store/host_disk_measurements.go -destination=internal/mocks/mock_host_disk_measurements.go -package=mocks
87-
mockgen -source=internal/store/diagnose_archive.go -destination=internal/mocks/mock_diagnose_archive.go -package=mocks
59+
go generate ./internal...
8860

8961
.PHONY: build
9062
build: ## Generate a binary in ./bin

internal/cli/atlas_dbusers_update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
func TestAtlasDBUserUpdate_Run(t *testing.T) {
2626
ctrl := gomock.NewController(t)
27-
mockStore := mocks.NewMockDatabaseUserStore(ctrl)
27+
mockStore := mocks.NewMockDatabaseUserUpdater(ctrl)
2828

2929
defer ctrl.Finish()
3030

internal/cli/config_set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
func TestConfigSet_Run(t *testing.T) {
2525
ctrl := gomock.NewController(t)
26-
mockStore := mocks.NewMockProfileSetSaver(ctrl)
26+
mockStore := mocks.NewMockSetSaver(ctrl)
2727
defer ctrl.Finish()
2828

2929
t.Run("valid prop", func(t *testing.T) {

internal/cli/ops_manager_clusters_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
func TestCloudManagerClustersCreate_Run(t *testing.T) {
2727
ctrl := gomock.NewController(t)
28-
mockStore := mocks.NewMockAutomationStore(ctrl)
28+
mockStore := mocks.NewMockAutomationPatcher(ctrl)
2929

3030
defer ctrl.Finish()
3131

internal/config/profile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"github.com/spf13/viper"
2424
)
2525

26+
//go:generate mockgen -destination=../mocks/mock_profile.go -package=mocks github.com/mongodb/mongocli/internal/config Setter,Saver,SetSaver,Getter,Config
27+
2628
type profile struct {
2729
name *string
2830
configDir string

internal/mocks/.keep

Whitespace-only changes.

internal/mocks/mock_agents.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mocks/mock_alert_configuration.go

Lines changed: 1 addition & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mocks/mock_alerts.go

Lines changed: 1 addition & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mocks/mock_automation.go

Lines changed: 1 addition & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)