Skip to content

Commit 54882f6

Browse files
A-725-Kpraveenkumar
authored andcommitted
Show MicroShift version as part of 'version' command
Extend existing unit tests to verify that also this field is present in the output, and API types and tests related to version.
1 parent 1a915c7 commit 54882f6

File tree

7 files changed

+36
-26
lines changed

7 files changed

+36
-26
lines changed

cmd/crc/cmd/version.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ func runPrintVersion(writer io.Writer, version *version, outputFormat string) er
3434
}
3535

3636
type version struct {
37-
Version string `json:"version"`
38-
Commit string `json:"commit"`
39-
OpenshiftVersion string `json:"openshiftVersion"`
37+
Version string `json:"version"`
38+
Commit string `json:"commit"`
39+
OpenshiftVersion string `json:"openshiftVersion"`
40+
MicroshiftVersion string `json:"microshiftVersion"`
4041
}
4142

4243
func defaultVersion() *version {
4344
return &version{
44-
Version: crcversion.GetCRCVersion(),
45-
Commit: crcversion.GetCommitSha(),
46-
OpenshiftVersion: crcversion.GetBundleVersion(crcPreset.OpenShift),
45+
Version: crcversion.GetCRCVersion(),
46+
Commit: crcversion.GetCommitSha(),
47+
OpenshiftVersion: crcversion.GetBundleVersion(crcPreset.OpenShift),
48+
MicroshiftVersion: crcversion.GetBundleVersion(crcPreset.Microshift),
4749
}
4850
}
4951

@@ -60,5 +62,6 @@ func (v *version) lines() []string {
6062
return []string{
6163
fmt.Sprintf("CRC version: %s+%s\n", v.Version, v.Commit),
6264
fmt.Sprintf("OpenShift version: %s\n", v.OpenshiftVersion),
65+
fmt.Sprintf("MicroShift version: %s\n", v.MicroshiftVersion),
6366
}
6467
}

cmd/crc/cmd/version_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@ import (
1010
func TestPlainVersion(t *testing.T) {
1111
out := new(bytes.Buffer)
1212
assert.NoError(t, runPrintVersion(out, &version{
13-
Version: "1.13",
14-
Commit: "aabbcc",
15-
OpenshiftVersion: "4.5.4",
13+
Version: "1.13",
14+
Commit: "aabbcc",
15+
OpenshiftVersion: "4.5.4",
16+
MicroshiftVersion: "4.16.0",
1617
}, ""))
1718
assert.Equal(t, `CRC version: 1.13+aabbcc
1819
OpenShift version: 4.5.4
20+
MicroShift version: 4.16.0
1921
`, out.String())
2022
}
2123

2224
func TestJsonVersion(t *testing.T) {
2325
out := new(bytes.Buffer)
2426
assert.NoError(t, runPrintVersion(out, &version{
25-
Version: "1.13",
26-
Commit: "aabbcc",
27-
OpenshiftVersion: "4.5.4",
27+
Version: "1.13",
28+
Commit: "aabbcc",
29+
OpenshiftVersion: "4.5.4",
30+
MicroshiftVersion: "4.16.0",
2831
}, "json"))
2932

30-
expected := `{"version": "1.13", "commit": "aabbcc", "openshiftVersion": "4.5.4"}`
33+
expected := `{"version": "1.13", "commit": "aabbcc", "openshiftVersion": "4.5.4", "microshiftVersion": "4.16.0"}`
3134
assert.JSONEq(t, expected, out.String())
3235
}

pkg/crc/api/api_client_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func TestVersion(t *testing.T) {
4848
assert.Equal(
4949
t,
5050
apiClient.VersionResult{
51-
CrcVersion: version.GetCRCVersion(),
52-
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
53-
CommitSha: version.GetCommitSha(),
51+
CrcVersion: version.GetCRCVersion(),
52+
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
53+
MicroshiftVersion: version.GetBundleVersion(preset.Microshift),
54+
CommitSha: version.GetCommitSha(),
5455
},
5556
vr,
5657
)

pkg/crc/api/api_http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ var testCases = []testCase{
265265
// version
266266
{
267267
request: get("version"),
268-
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift))),
268+
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","MicroshiftVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift), version.GetBundleVersion(preset.Microshift))),
269269
},
270270

271271
// version never fails

pkg/crc/api/client/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
)
88

99
type VersionResult struct {
10-
CrcVersion string
11-
CommitSha string
12-
OpenshiftVersion string
10+
CrcVersion string
11+
CommitSha string
12+
OpenshiftVersion string
13+
MicroshiftVersion string
1314
}
1415

1516
type StartResult struct {

pkg/crc/api/handlers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC
136136

137137
func (h *Handler) GetVersion(c *context) error {
138138
return c.JSON(http.StatusOK, &client.VersionResult{
139-
CrcVersion: version.GetCRCVersion(),
140-
CommitSha: version.GetCommitSha(),
141-
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
139+
CrcVersion: version.GetCRCVersion(),
140+
CommitSha: version.GetCommitSha(),
141+
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
142+
MicroshiftVersion: version.GetBundleVersion(preset.Microshift),
142143
})
143144
}
144145

test/integration/testsuite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import (
1717
)
1818

1919
type VersionAnswer struct {
20-
Version string `json:"version"`
21-
Commit string `json:"commit"`
22-
OpenshiftVersion string `json:"openshiftVersion"`
20+
Version string `json:"version"`
21+
Commit string `json:"commit"`
22+
OpenshiftVersion string `json:"openshiftVersion"`
23+
MicroshiftVersion string `json:"microshiftVersion"`
2324
}
2425

2526
var credPath string

0 commit comments

Comments
 (0)