Skip to content

Commit

Permalink
Show MicroShift version as part of 'version' command
Browse files Browse the repository at this point in the history
Extend existing unit tests to verify that also this field is present in
the output, and API types and tests related to version.
  • Loading branch information
A-725-K authored and praveenkumar committed Jul 16, 2024
1 parent 1a915c7 commit 54882f6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
15 changes: 9 additions & 6 deletions cmd/crc/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ func runPrintVersion(writer io.Writer, version *version, outputFormat string) er
}

type version struct {
Version string `json:"version"`
Commit string `json:"commit"`
OpenshiftVersion string `json:"openshiftVersion"`
Version string `json:"version"`
Commit string `json:"commit"`
OpenshiftVersion string `json:"openshiftVersion"`
MicroshiftVersion string `json:"microshiftVersion"`
}

func defaultVersion() *version {
return &version{
Version: crcversion.GetCRCVersion(),
Commit: crcversion.GetCommitSha(),
OpenshiftVersion: crcversion.GetBundleVersion(crcPreset.OpenShift),
Version: crcversion.GetCRCVersion(),
Commit: crcversion.GetCommitSha(),
OpenshiftVersion: crcversion.GetBundleVersion(crcPreset.OpenShift),
MicroshiftVersion: crcversion.GetBundleVersion(crcPreset.Microshift),
}
}

Expand All @@ -60,5 +62,6 @@ func (v *version) lines() []string {
return []string{
fmt.Sprintf("CRC version: %s+%s\n", v.Version, v.Commit),
fmt.Sprintf("OpenShift version: %s\n", v.OpenshiftVersion),
fmt.Sprintf("MicroShift version: %s\n", v.MicroshiftVersion),
}
}
17 changes: 10 additions & 7 deletions cmd/crc/cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import (
func TestPlainVersion(t *testing.T) {
out := new(bytes.Buffer)
assert.NoError(t, runPrintVersion(out, &version{
Version: "1.13",
Commit: "aabbcc",
OpenshiftVersion: "4.5.4",
Version: "1.13",
Commit: "aabbcc",
OpenshiftVersion: "4.5.4",
MicroshiftVersion: "4.16.0",
}, ""))
assert.Equal(t, `CRC version: 1.13+aabbcc
OpenShift version: 4.5.4
MicroShift version: 4.16.0
`, out.String())
}

func TestJsonVersion(t *testing.T) {
out := new(bytes.Buffer)
assert.NoError(t, runPrintVersion(out, &version{
Version: "1.13",
Commit: "aabbcc",
OpenshiftVersion: "4.5.4",
Version: "1.13",
Commit: "aabbcc",
OpenshiftVersion: "4.5.4",
MicroshiftVersion: "4.16.0",
}, "json"))

expected := `{"version": "1.13", "commit": "aabbcc", "openshiftVersion": "4.5.4"}`
expected := `{"version": "1.13", "commit": "aabbcc", "openshiftVersion": "4.5.4", "microshiftVersion": "4.16.0"}`
assert.JSONEq(t, expected, out.String())
}
7 changes: 4 additions & 3 deletions pkg/crc/api/api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ func TestVersion(t *testing.T) {
assert.Equal(
t,
apiClient.VersionResult{
CrcVersion: version.GetCRCVersion(),
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
CommitSha: version.GetCommitSha(),
CrcVersion: version.GetCRCVersion(),
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
MicroshiftVersion: version.GetBundleVersion(preset.Microshift),
CommitSha: version.GetCommitSha(),
},
vr,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/api/api_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ var testCases = []testCase{
// version
{
request: get("version"),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift))),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","MicroshiftVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift), version.GetBundleVersion(preset.Microshift))),
},

// version never fails
Expand Down
7 changes: 4 additions & 3 deletions pkg/crc/api/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

type VersionResult struct {
CrcVersion string
CommitSha string
OpenshiftVersion string
CrcVersion string
CommitSha string
OpenshiftVersion string
MicroshiftVersion string
}

type StartResult struct {
Expand Down
7 changes: 4 additions & 3 deletions pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC

func (h *Handler) GetVersion(c *context) error {
return c.JSON(http.StatusOK, &client.VersionResult{
CrcVersion: version.GetCRCVersion(),
CommitSha: version.GetCommitSha(),
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
CrcVersion: version.GetCRCVersion(),
CommitSha: version.GetCommitSha(),
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
MicroshiftVersion: version.GetBundleVersion(preset.Microshift),
})
}

Expand Down
7 changes: 4 additions & 3 deletions test/integration/testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
)

type VersionAnswer struct {
Version string `json:"version"`
Commit string `json:"commit"`
OpenshiftVersion string `json:"openshiftVersion"`
Version string `json:"version"`
Commit string `json:"commit"`
OpenshiftVersion string `json:"openshiftVersion"`
MicroshiftVersion string `json:"microshiftVersion"`
}

var credPath string
Expand Down

0 comments on commit 54882f6

Please sign in to comment.