Skip to content

Commit

Permalink
Merge pull request #3599 from hp685/main
Browse files Browse the repository at this point in the history
fix kind version unit test failures for released versions
  • Loading branch information
BenTheElder authored May 2, 2024
2 parents a53193a + 4b69508 commit 19df3db
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/kind/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const versionCore = "0.23.0"

// versionPreRelease is the base pre-release portion of the kind CLI version per
// Semantic Versioning 2.0.0
const versionPreRelease = "alpha"
var versionPreRelease = "alpha"

// gitCommitCount count the commits since the last release.
// It is injected at build time.
Expand Down
65 changes: 45 additions & 20 deletions pkg/cmd/kind/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,53 @@ func TestTruncate(t *testing.T) {

func TestVersion(t *testing.T) {
tests := []struct {
name string
gitCommit string
gitCommitCount string
want string
name string
versionPreRelease string
gitCommit string
gitCommitCount string
want string
}{
{
name: "With git commit count and with commit hash",
gitCommit: "mocked-hash",
gitCommitCount: "mocked-count",
want: versionCore + "-" + versionPreRelease + "." + "mocked-count" + "+" + "mocked-hash",
name: "With git commit count and with commit hash",
versionPreRelease: "alpha",
gitCommit: "mocked-hash",
gitCommitCount: "mocked-count",
want: versionCore + "-" + "alpha" + "." + "mocked-count" + "+" + "mocked-hash",
},
{
name: "Without git commit count and and with hash",
gitCommit: "mocked-hash",
gitCommitCount: "",
want: versionCore + "-" + versionPreRelease + "+" + "mocked-hash",
name: "Without git commit count and and with hash",
versionPreRelease: "beta",
gitCommit: "mocked-hash",
gitCommitCount: "",
want: versionCore + "-" + "beta" + "+" + "mocked-hash",
},
{
name: "Without git commit hash and with commit count",
gitCommit: "",
gitCommitCount: "mocked-count",
want: versionCore + "-" + versionPreRelease + "." + "mocked-count",
name: "Without git commit hash and with commit count",
versionPreRelease: "alpha",
gitCommit: "",
gitCommitCount: "mocked-count",
want: versionCore + "-" + "alpha" + "." + "mocked-count",
},
{
name: "Without git commit hash and without commit count",
gitCommit: "",
gitCommitCount: "",
want: versionCore + "-" + versionPreRelease,
name: "Without git commit hash and without commit count",
versionPreRelease: "alpha",
gitCommit: "",
gitCommitCount: "",
want: versionCore + "-" + "alpha",
},
{
name: "Without pre release version",
versionPreRelease: "",
gitCommit: "",
gitCommitCount: "",
want: versionCore,
},
{
name: "Without pre release version and with git commit hash and count",
versionPreRelease: "",
gitCommit: "mocked-commit",
gitCommitCount: "mocked-count",
want: versionCore,
},
}
for _, tt := range tests {
Expand All @@ -110,6 +129,12 @@ func TestVersion(t *testing.T) {
gitCommitCount = gitCommitCountBackup
}()
}

versionPreReleaseBackup := versionPreRelease
versionPreRelease = tt.versionPreRelease
defer func() {
versionPreRelease = versionPreReleaseBackup
}()
if got := Version(); got != tt.want {
t.Errorf("Version() = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 19df3db

Please sign in to comment.