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

chore(all): simplify mocks generation #1413

Merged
merged 14 commits into from
Jan 7, 2025
Merged

chore(all): simplify mocks generation #1413

merged 14 commits into from
Jan 7, 2025

Conversation

qdm12
Copy link
Collaborator

@qdm12 qdm12 commented Dec 27, 2024

Why this should be merged

💁 Sibling PR for coreth so both repositories would look similar in this aspect

  • Localized mockgen commands in the package where they are needed
  • Generate mocks from your IDE directly
  • Platform independent way of generating mocks
  • Check automatically mocks are kept up to date with their matching interfaces
  • Check automatically mocks all have a matching source controlled generation command
  • Remove license headers for generated mocks
  • Generating mocks section added in contributing document
  • Use same mockgen version as specified in go.mod

How this works

  • New mocks_generate_test.go file per package where mocks need to be generated, containing only //go:generate commands for mock generation. Each command is relative to the current package directory
  • Use //go:generate go run go.uber.org/mock/mockgen to avoid requiring to pre-install mockgen
  • no shell script, just go command needed with go generate -run "mockgen" ./...
    • Remove now unneeded scripts/mocks.gen.sh and scripts/mocks.mockgen.txt
  • Add step to CI test job to check:
    • mocks are up to date, by re-generating all of them and running a git add --intent-to-add --all and git diff --exit-code
    • mocks each have a source controlled //go:generate generation command, by removing all of them before re-generating them
  • Documentation added to .github/CONTRIBUTING.md
  • Specify tools.go with anonymous import to allow using the same mockgen version automatically as the one specified in go.mod

How this was tested

CI passing (Golang unit tests > Mocks are up to date)

Need to be documented?

Yes in .github/CONTRIBUTING.md

Need to update RELEASES.md?

Not really

@qdm12 qdm12 changed the title chore(scripts): simplify mock.gen.sh to use go generate commands chore(scripts): simplify mock.gen.sh to use go generate commands Dec 27, 2024
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch from 3edebbc to a37996e Compare December 27, 2024 11:29
@qdm12 qdm12 marked this pull request as ready for review December 27, 2024 11:48
@qdm12 qdm12 requested review from ceyonur, darioush and a team as code owners December 27, 2024 11:48
license_header Outdated Show resolved Hide resolved
scripts/mock.gen.sh Outdated Show resolved Hide resolved
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch 3 times, most recently from 0a20685 to b466ccb Compare December 31, 2024 12:58
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch from f7b7acb to c2c5fb0 Compare January 6, 2025 09:44
@qdm12 qdm12 requested a review from ceyonur January 6, 2025 10:54
@qdm12 qdm12 changed the title chore(scripts): simplify mock.gen.sh to use go generate commands chore(scripts): simplify mocks generation Jan 6, 2025
@qdm12 qdm12 changed the title chore(scripts): simplify mocks generation chore(all): simplify mocks generation Jan 6, 2025
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch from c2c5fb0 to d24a3bd Compare January 7, 2025 10:27
qdm12 added 4 commits January 7, 2025 11:27
- requires a `tools.go` blank importing golang.org/x/mod/semver in order to have the `golang.org/x/mod` dependency satisfied for mockgen v0.4
- not used anywhere
- different from avalanchego
- does not work on windows' bash
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch from d24a3bd to e74c80b Compare January 7, 2025 10:27
Copy link
Collaborator

@ceyonur ceyonur left a comment

Choose a reason for hiding this comment

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

LGTM

@qdm12 qdm12 merged commit 1fdaab7 into master Jan 7, 2025
13 checks passed
@qdm12 qdm12 deleted the qdm12/mock-gen-script branch January 7, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants