From ad20e86a2da490d257c44f4e2f904eae34fa1557 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 22 Nov 2024 19:07:46 +0530 Subject: [PATCH] fix (status) : Log info in CRC status for OKD preset (#3626) 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 --- cmd/crc/cmd/status.go | 10 +++++++--- cmd/crc/cmd/status_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/cmd/crc/cmd/status.go b/cmd/crc/cmd/status.go index c294ceb6a6..a53c06de07 100644 --- a/cmd/crc/cmd/status.go +++ b/cmd/crc/cmd/status.go @@ -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 { diff --git a/cmd/crc/cmd/status_test.go b/cmd/crc/cmd/status_test.go index 925a1539b4..3c0a4dc408 100644 --- a/cmd/crc/cmd/status_test.go +++ b/cmd/crc/cmd/status_test.go @@ -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) + }) + } +}