-
Notifications
You must be signed in to change notification settings - Fork 88
tets: test mock generation works #1029
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| name: Check Mock Generation | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| jobs: | ||
| mocks: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| - name: Install Go | ||
| uses: actions/setup-go@v2 | ||
| with: | ||
| go-version: 1.17 | ||
| - name: Intsall go-mock | ||
| run: go install github.com/golang/mock/mockgen@latest | ||
| - name: Generate mocks | ||
| run: make gen-mocks | ||
| - name: Check for uncommited files | ||
| run: | | ||
| export FILES=$(git ls-files -o -m --directory --exclude-standard --no-empty-directory) | ||
| export LINES=$(echo "$FILES" | awk 'NF' | wc -l) | ||
| if [ $LINES -ne 0 ]; then | ||
| echo "Detected files that need to be committed:" | ||
| echo "$FILES" | sed -e "s/^/ /" | ||
| echo "" | ||
| echo "Try running: make gen-mocks" | ||
| exit 1 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,14 @@ package latestrelease | |
| import ( | ||
| "context" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/google/go-github/v42/github" | ||
| "github.com/mongodb/mongocli/internal/version" | ||
| ) | ||
|
|
||
| //go:generate mockgen -destination=../mocks/mock_release_version.go -package=mocks github.com/mongodb/mongocli/internal/version VersionFinder | ||
| //go:generate mockgen -destination=../mocks/mock_release_version.go -package=mocks github.com/mongodb/mongocli/internal/latestrelease VersionFinder | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix to mock generation |
||
|
|
||
| type VersionFinder interface { | ||
| HasNewVersionAvailable(v, tool string) (newVersionAvailable bool, newVersion string, err error) | ||
|
|
@@ -45,14 +46,25 @@ func versionFromTag(release *github.RepositoryRelease, toolName string) string { | |
| return release.GetTagName() | ||
| } | ||
|
|
||
| const ( | ||
| mongoCLI = "mongocli" | ||
| atlasCLI = "atlascli" | ||
| ) | ||
|
Comment on lines
+49
to
+52
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive by these were being imported from the |
||
|
|
||
| func isValidTagForTool(tag, tool string) bool { | ||
| if tool == version.MongoCLI { | ||
| return !strings.Contains(tag, version.AtlasCLI) | ||
| if tool == mongoCLI { | ||
| return !strings.Contains(tag, atlasCLI) | ||
| } | ||
| return strings.Contains(tag, tool) | ||
| } | ||
|
|
||
| func (s *latestReleaseVersionFinder) searchLatestVersionPerTool(currentVersion *semver.Version, toolName string) (bool, *version.ReleaseInformation, error) { | ||
| // ReleaseInformation Release information. | ||
| type ReleaseInformation struct { | ||
| Version string | ||
| PublishedAt time.Time | ||
| } | ||
|
Comment on lines
+62
to
+65
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, imported from |
||
|
|
||
| func (s *latestReleaseVersionFinder) searchLatestVersionPerTool(currentVersion *semver.Version, toolName string) (bool, *ReleaseInformation, error) { | ||
| release, err := s.r.LatestWithCriteria(minPageSize, isValidTagForTool, toolName) | ||
|
|
||
| if err != nil || release == nil { | ||
|
|
@@ -66,7 +78,7 @@ func (s *latestReleaseVersionFinder) searchLatestVersionPerTool(currentVersion * | |
| } | ||
|
|
||
| if currentVersion.Compare(v) < 0 { | ||
| return true, &version.ReleaseInformation{ | ||
| return true, &ReleaseInformation{ | ||
| Version: v.Original(), | ||
| PublishedAt: release.GetPublishedAt().Time, | ||
| }, nil | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,22 +14,8 @@ | |
|
|
||
| package version | ||
|
|
||
| import "time" | ||
|
|
||
| const ( | ||
| MongoCLI = "mongocli" | ||
| AtlasCLI = "atlascli" | ||
| owner = "mongodb" | ||
| ) | ||
|
Comment on lines
-19
to
-23
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved closer to where needed |
||
|
|
||
| // Version for CLI. | ||
| var Version string | ||
|
|
||
| // GitCommit git sha of the build. | ||
| var GitCommit string | ||
|
|
||
| // ReleaseInformation Release information. | ||
| type ReleaseInformation struct { | ||
| Version string | ||
| PublishedAt time.Time | ||
| } | ||
|
Comment on lines
-32
to
-35
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved closer to where needed |
||
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.
inspired by the docs check