Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (status) : Log info in CRC status for OKD preset (#3626) #4479

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}
Loading