Skip to content

Commit

Permalink
fix (status) : Log info in CRC status for OKD preset (#3626)
Browse files Browse the repository at this point in the history
Currently `crc status` only logs information for OpenShift and
MicroShift presets only. We should also log cluster information for OKD
preset.

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Dec 9, 2024
1 parent 3ec0a44 commit 0d6387d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,15 @@ func (s *status) prettyPrintTo(writer io.Writer) error {
{"CRC VM", s.CrcStatus},
}

if s.Preset == preset.OpenShift {
switch s.Preset {
case preset.OpenShift:
lines = append(lines, line{"OpenShift", openshiftStatus(s)})
}
if s.Preset == preset.Microshift {
case preset.Microshift:
lines = append(lines, line{"MicroShift", openshiftStatus(s)})
case preset.OKD:
lines = append(lines, line{"OpenShift/OKD", openshiftStatus(s)})
default:
panic(fmt.Sprintf("unknown preset provided : %s (expecting OpenShift, MicroShift, or OKD) ", s.Preset))
}

if s.RAMSize != -1 && s.RAMUsage != -1 {
Expand Down
38 changes: 38 additions & 0 deletions cmd/crc/cmd/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,41 @@ Cache Directory: %s
`
assert.Equal(t, fmt.Sprintf(expected, cacheDir), out.String())
}

func TestCrcStatusShouldLogInformationForConfiguredPresets(t *testing.T) {
tests := []struct {
name string
preset preset.Preset
statusLog string
}{
{"OpenShift preset should log OpenShift", preset.OpenShift, "OpenShift: Running (v4.5.1)"},
{"OKD preset should log OpenShift/OKD", preset.OKD, "OpenShift/OKD: Running (v4.5.1)"},
{"MicroShift preset should log MicroShift", preset.Microshift, "MicroShift: Running (v4.5.1)"},
{"Unknown preset should log OpenShift", preset.ParsePreset("unknown"), "OpenShift: Running (v4.5.1)"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Given
cacheDir := t.TempDir()
out := new(bytes.Buffer)
client := mocks.NewClient(t)
require.NoError(t, os.WriteFile(filepath.Join(cacheDir, "crc.qcow2"), make([]byte, 10000), 0600))
client.On("Status").Return(apiClient.ClusterStatusResult{
CrcStatus: string(state.Running),
OpenshiftStatus: string(types.OpenshiftRunning),
OpenshiftVersion: "4.5.1",
Preset: tt.preset,
}, nil)

// When
err := runStatus(out, &daemonclient.Client{
APIClient: client,
}, cacheDir, "", false)

// Then
assert.NoError(t, err)
assert.Contains(t, out.String(), tt.statusLog)
})
}
}

0 comments on commit 0d6387d

Please sign in to comment.