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 authored and praveenkumar committed Dec 23, 2024
1 parent e119f1c commit c72a45f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
7 changes: 1 addition & 6 deletions cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ func (s *status) prettyPrintTo(writer io.Writer) error {
{"CRC VM", s.CrcStatus},
}

if s.Preset == preset.OpenShift {
lines = append(lines, line{"OpenShift", openshiftStatus(s)})
}
if s.Preset == preset.Microshift {
lines = append(lines, line{"MicroShift", openshiftStatus(s)})
}
lines = append(lines, line{s.Preset.ForDisplay(), openshiftStatus(s)})

if s.RAMSize != -1 && s.RAMUsage != -1 {
lines = append(lines, line{"RAM Usage", fmt.Sprintf(
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 OKD", preset.OKD, "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 c72a45f

Please sign in to comment.