-
Notifications
You must be signed in to change notification settings - Fork 0
test(storage): Replace handwritten storage mocks with gomock bazel rule #79
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
decd422
test(storage): Replace handwritten storage mocks with gomock bazel rule
manjari25 62f47bd
add gazelle ignore to storage mock BUILD.bazel
manjari25 2226415
add a readme for new store additions
manjari25 1d77cf8
add claude instructions for mock
manjari25 a579292
Merge branch 'main' into manjari/gomock-for-storage
manjari25 5d43a79
Merge branch 'main' into manjari/gomock-for-storage
manjari25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| load("@rules_go//extras:gomock.bzl", "gomock") | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| _MOCKGEN = "@org_uber_go_mock//mockgen" | ||
|
|
||
| gomock( | ||
| name = "mock_storage_src", | ||
| out = "storage_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:storage.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| gomock( | ||
| name = "mock_request_store_src", | ||
| out = "request_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:request_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| gomock( | ||
| name = "mock_change_provider_store_src", | ||
| out = "change_provider_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:change_provider_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| gomock( | ||
| name = "mock_batch_store_src", | ||
| out = "batch_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:batch_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| gomock( | ||
| name = "mock_batch_dependent_store_src", | ||
| out = "batch_dependent_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:batch_dependent_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| gomock( | ||
| name = "mock_build_store_src", | ||
| out = "build_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:build_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| gomock( | ||
| name = "mock_speculation_tree_store_src", | ||
| out = "speculation_tree_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:speculation_tree_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
|
|
||
| # gazelle:ignore | ||
| go_library( | ||
| name = "mock", | ||
| srcs = [ | ||
| ":mock_batch_dependent_store_src", | ||
| ":mock_batch_store_src", | ||
| ":mock_build_store_src", | ||
| ":mock_change_provider_store_src", | ||
| ":mock_request_store_src", | ||
| ":mock_speculation_tree_store_src", | ||
| ":mock_storage_src", | ||
| ], | ||
| importpath = "github.com/uber/submitqueue/extension/storage/mock", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//entity", | ||
| "//extension/storage", | ||
| "@org_uber_go_mock//gomock", | ||
| ], | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Storage Mocks | ||
|
|
||
| Generated mocks for all `extension/storage` interfaces using [gomock](https://github.com/uber-go/mock). | ||
|
|
||
| Mocks are **not checked in** — they are generated at build time by the Bazel `gomock` rule. | ||
|
|
||
| ## Adding a new store interface | ||
|
|
||
| When a new store interface file is added to `extension/storage/`: | ||
|
|
||
| 1. Add a `//go:generate` directive to the new file: | ||
| ```go | ||
| //go:generate mockgen -source=new_store.go -destination=mock/new_store.go -package=mock | ||
| ``` | ||
|
|
||
| 2. Add the file to `exports_files` in `extension/storage/BUILD.bazel`. | ||
|
|
||
| 3. Add a new `gomock` rule in `extension/storage/mock/BUILD.bazel`: | ||
| ```starlark | ||
| gomock( | ||
| name = "mock_new_store_src", | ||
| out = "new_store_mock.go", | ||
| mockgen_tool = _MOCKGEN, | ||
| package = "mock", | ||
| source = "//extension/storage:new_store.go", | ||
| source_importpath = "github.com/uber/submitqueue/extension/storage", | ||
| ) | ||
| ``` | ||
|
|
||
| 4. Add the new rule target to the `go_library` srcs in the same file: | ||
| ```starlark | ||
| go_library( | ||
| name = "mock", | ||
| srcs = [ | ||
| ... | ||
| ":mock_new_store_src", | ||
| ], | ||
| ... | ||
| ) | ||
| ``` | ||
|
|
||
| > **Note:** This BUILD.bazel uses `# gazelle:ignore`, so gazelle will not update it automatically. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.