Skip to content

CLOUDP-62054: replace mock generation in make with go generate #187

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

Merged
merged 2 commits into from
May 25, 2020
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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ We provide a git pre-commit hook to format and check the code, to install it run

### Generating Mocks

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

Choose a reason for hiding this comment

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

💯


### Adding a New Command

Expand Down
30 changes: 1 addition & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,7 @@ addlicense:
.PHONY: gen-mocks
gen-mocks: ## Generate mocks
@echo "==> Generating mocks"
mockgen -source=internal/config/profile.go -destination=internal/mocks/mock_profile.go -package=mocks
mockgen -source=internal/store/alert_configuration.go -destination=internal/mocks/mock_alert_configuration.go -package=mocks
mockgen -source=internal/store/automation.go -destination=internal/mocks/mock_automation.go -package=mocks
mockgen -source=internal/store/clusters.go -destination=internal/mocks/mock_clusters.go -package=mocks
mockgen -source=internal/store/database_users.go -destination=internal/mocks/mock_database_users.go -package=mocks
mockgen -source=internal/store/project_ip_whitelist.go -destination=internal/mocks/mock_project_ip_whitelist.go -package=mocks
mockgen -source=internal/store/projects.go -destination=internal/mocks/mock_projects.go -package=mocks
mockgen -source=internal/store/organizations.go -destination=internal/mocks/mock_organizations.go -package=mocks
mockgen -source=internal/store/owners.go -destination=internal/mocks/mock_owners.go -package=mocks
mockgen -source=internal/store/continuous_snapshots.go -destination=internal/mocks/mock_continuous_snapshots.go -package=mocks
mockgen -source=internal/store/continuous_jobs.go -destination=internal/mocks/mock_continuous_jobs.go -package=mocks
mockgen -source=internal/store/agents.go -destination=internal/mocks/mock_agents.go -package=mocks
mockgen -source=internal/store/checkpoints.go -destination=internal/mocks/mock_checkpoints.go -package=mocks
mockgen -source=internal/store/alerts.go -destination=internal/mocks/mock_alerts.go -package=mocks
mockgen -source=internal/store/global_alerts.go -destination=internal/mocks/mock_global_alerts.go -package=mocks
mockgen -source=internal/store/events.go -destination=internal/mocks/mock_events.go -package=mocks
mockgen -source=internal/store/process_measurements.go -destination=internal/mocks/mock_process_measurements.go -package=mocks
mockgen -source=internal/store/process_disks.go -destination=internal/mocks/mock_process_disks.go -package=mocks
mockgen -source=internal/store/process_disk_measurements.go -destination=internal/mocks/mock_process_disk_measurements.go -package=mocks
mockgen -source=internal/store/process_databases.go -destination=internal/mocks/mock_process_databases.go -package=mocks
mockgen -source=internal/store/host_measurements.go -destination=internal/mocks/mock_host_measurements.go -package=mocks
mockgen -source=internal/store/indexes.go -destination=internal/mocks/mock_indexes.go -package=mocks
mockgen -source=internal/store/processes.go -destination=internal/mocks/mock_processes.go -package=mocks
mockgen -source=internal/store/logs.go -destination=internal/mocks/mock_logs.go -package=mocks
mockgen -source=internal/store/hosts.go -destination=internal/mocks/mock_hosts.go -package=mocks
mockgen -source=internal/store/host_databases.go -destination=internal/mocks/mock_host_databases.go -package=mocks
mockgen -source=internal/store/host_disks.go -destination=internal/mocks/mock_host_disks.go -package=mocks
mockgen -source=internal/store/host_disk_measurements.go -destination=internal/mocks/mock_host_disk_measurements.go -package=mocks
mockgen -source=internal/store/diagnose_archive.go -destination=internal/mocks/mock_diagnose_archive.go -package=mocks
go generate ./internal...

.PHONY: build
build: ## Generate a binary in ./bin
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/atlas_dbusers_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func TestAtlasDBUserUpdate_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockDatabaseUserStore(ctrl)
mockStore := mocks.NewMockDatabaseUserUpdater(ctrl)

defer ctrl.Finish()

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/config_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestConfigSet_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockProfileSetSaver(ctrl)
mockStore := mocks.NewMockSetSaver(ctrl)
defer ctrl.Finish()

t.Run("valid prop", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/ops_manager_clusters_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func TestCloudManagerClustersCreate_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockAutomationStore(ctrl)
mockStore := mocks.NewMockAutomationPatcher(ctrl)

defer ctrl.Finish()

Expand Down
2 changes: 2 additions & 0 deletions internal/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/spf13/viper"
)

//go:generate mockgen -destination=../mocks/mock_profile.go -package=mocks github.com/mongodb/mongocli/internal/config Setter,Saver,SetSaver,Getter,Config

type profile struct {
name *string
configDir string
Expand Down
Empty file added internal/mocks/.keep
Empty file.
2 changes: 1 addition & 1 deletion internal/mocks/mock_agents.go

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

99 changes: 1 addition & 98 deletions internal/mocks/mock_alert_configuration.go

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

70 changes: 1 addition & 69 deletions internal/mocks/mock_alerts.go

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

107 changes: 1 addition & 106 deletions internal/mocks/mock_automation.go

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

Loading