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

build(core/testing): migrate to go.uber.org/mock #22314

Closed
wants to merge 1 commit into from

Conversation

islishude
Copy link
Contributor

@islishude islishude commented Oct 19, 2024

Description

#22313

Many internal packages depends on core/testing, we should migrate it first and then bump the its version for the packages.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Chores
    • Updated the mock service dependencies to improve compatibility and maintainability.
    • Removed outdated dependency on github.com/golang/mock and added go.uber.org/mock.
  • Refactor
    • Enhanced mock implementations with new fields for improved clarity and updated method signatures for better type alignment.

@islishude islishude requested a review from a team as a code owner October 19, 2024 00:00
Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

📝 Walkthrough

Walkthrough

The changes involve updates to the core/testing/gas/service_mocks.go and core/testing/go.mod files. The import statement for the gomock package has been changed from github.com/golang/mock/gomock to go.uber.org/mock/gomock. Additionally, the MockService and MockMeter structs now include a new field, and several method signatures have been updated to replace interface{} with any. The go.mod file reflects the removal of the old gomock dependency and the addition of the new one.

Changes

File Change Summary
core/testing/gas/service_mocks.go - Updated import statement for gomock package.
- Added isgomock struct{} to MockService and MockMeter.
- Updated method signatures to use any instead of interface{}.
core/testing/go.mod - Removed dependency on github.com/golang/mock v1.6.0.
- Added dependency on go.uber.org/mock v0.5.0.

Suggested labels

backport/v0.52.x

Suggested reviewers

  • sontrinh16
  • tac0turtle

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
core/testing/go.mod (1)

Go Version Mismatch and Incomplete Mock Package Migration

  • The Go version in core/testing/go.mod is set to 1.23, which exceeds the latest stable release (1.21) as of October 2023. Please verify if this is intentional or update it to a supported version.
  • The migration to go.uber.org/mock is incomplete. There are remaining imports of the old mock package (github.com/golang/mock/gomock) in multiple files. Please ensure all references to the old mock package are removed.
🔗 Analysis chain

Line range hint 3-3: Verify the Go version

The Go version is set to 1.23, which seems unusually high. As of October 2023, the latest stable version of Go is 1.21. Please verify if this is intentional or if it should be adjusted to a current stable version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the Go version used in the project and compare with the one in go.mod

# Get the Go version from go.mod
go_mod_version=$(grep "^go " core/testing/go.mod | awk '{print $2}')

echo "Go version in go.mod: $go_mod_version"

# Get the current Go version
current_go_version=$(go version | awk '{print $3}' | sed 's/go//')

echo "Current Go version: $current_go_version"

# Compare versions
if [ "$go_mod_version" != "$current_go_version" ]; then
    echo "Warning: Go version mismatch between go.mod and the current Go installation"
fi

Length of output: 28593

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f84b585 and c852579.

⛔ Files ignored due to path filters (1)
  • core/testing/go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • core/testing/gas/service_mocks.go (7 hunks)
  • core/testing/go.mod (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
core/testing/gas/service_mocks.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (7)
core/testing/go.mod (1)

8-8: LGTM: Mock package migration

The change from github.com/golang/mock to go.uber.org/mock aligns with the PR objective. This migration is a positive step, as go.uber.org/mock is actively maintained and provides improved features.

However, please ensure that all usages of the mock package in the codebase have been updated to use the new import path and any changed APIs.

#!/bin/bash
# Description: Verify that all usages of the mock package have been updated

# Check for any remaining imports of the old mock package
old_imports=$(rg --type go "github.com/golang/mock")

if [ -n "$old_imports" ]; then
    echo "Warning: Found remaining imports of the old mock package:"
    echo "$old_imports"
else
    echo "No remaining imports of the old mock package found."
fi

# Check for usages of the new mock package
new_imports=$(rg --type go "go.uber.org/mock")

if [ -n "$new_imports" ]; then
    echo "Found usages of the new mock package:"
    echo "$new_imports"
else
    echo "Warning: No usages of the new mock package found. Ensure the migration is complete."
fi
core/testing/gas/service_mocks.go (6)

17-17: LGTM: Import statement updated correctly.

The import statement has been successfully updated to use go.uber.org/mock/gomock, which aligns with the PR objective of migrating to go.uber.org/mock.


24-24: LGTM: New isgomock field added.

The addition of the isgomock struct{} field to the MockService struct is consistent with the new mock implementation. This field serves as a marker for the mock type and doesn't affect the existing functionality.


53-55: LGTM: Method signature updated to use any.

The GasConfig method signature has been updated to use any instead of interface{}. This change aligns with modern Go practices and improves code readability without altering functionality.


67-69: LGTM: Method signature updated consistently.

The GasMeter method signature has been updated to use any, consistent with the previous changes. This maintains consistency throughout the mock implementation.


76-76: LGTM: Consistent updates to MockMeter struct and method signatures.

The changes to the MockMeter struct and its method signatures are consistent with the previous updates:

  1. The isgomock struct{} field has been added to the MockMeter struct.
  2. The Consume and Refund method signatures in MockMeterMockRecorder have been updated to use any.

These changes maintain consistency across the mock implementation and align with modern Go practices.

Also applies to: 105-107, 147-149


Line range hint 1-165: Summary: Successful migration to go.uber.org/mock

The changes in this file successfully implement the migration to go.uber.org/mock:

  1. The import statement has been updated to use the new package.
  2. New isgomock fields have been added to mock structs for type marking.
  3. Method signatures have been consistently updated to use any instead of interface{}.

These changes improve code readability and align with modern Go practices without altering the functionality of the mocks. The migration appears to be complete and correct for this file.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Shouldn't we converge all of our mocks to this? Check out mockgen.sh under scripts

@islishude
Copy link
Contributor Author

Shouldn't we converge all of our mocks to this? Check out mockgen.sh under scripts

See #22315

since the other packages depend on this core/testing package, I have to migrate this one first.

@julienrbrt
Copy link
Member

Right, but you still need to run make mocks

@islishude
Copy link
Contributor Author

you still need to run make mocks

the core/testing/gas/service_mocks.go is already updated

@julienrbrt
Copy link
Member

@islishude
Copy link
Contributor Author

I'm not sure how to solve the ci issue.

if I update the make mocks command, It will update all of the modules.

but x/auth/ante/sigverify_test.go requires the update of the core/testing module.

cannot use ctrl (variable of type *"go.uber.org/mock/gomock".Controller) as *"github.com/golang/mock/gomock".Controller value in argument to gastestutil.NewMockMeter

@islishude
Copy link
Contributor Author

I'm going to close this.

I will retain the golang/mock for the x/auth module.

@islishude islishude closed this Oct 20, 2024
@islishude islishude deleted the build-uber-mockgen branch October 21, 2024 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants