diff --git a/cmd/crc/cmd/console.go b/cmd/crc/cmd/console.go index bdd5c6a385..39be0e400e 100644 --- a/cmd/crc/cmd/console.go +++ b/cmd/crc/cmd/console.go @@ -6,6 +6,8 @@ import ( "io" "os" + "github.com/crc-org/crc/v2/pkg/crc/preset" + "github.com/crc-org/crc/v2/pkg/crc/api/client" "github.com/crc-org/crc/v2/pkg/crc/daemonclient" crcErrors "github.com/crc-org/crc/v2/pkg/crc/errors" @@ -44,6 +46,9 @@ func showConsole(client *daemonclient.Client) (*client.ConsoleResult, error) { func runConsole(writer io.Writer, client *daemonclient.Client, consolePrintURL, consolePrintCredentials bool, outputFormat string) error { result, err := showConsole(client) + if err == nil && result.ClusterConfig.ClusterType == preset.Microshift { + err = fmt.Errorf("error : this option is not supported for microshift preset. Please refer to the documentation for a list of supported presets for using this option") + } return render(&consoleResult{ Success: err == nil, state: toState(result), diff --git a/cmd/crc/cmd/console_test.go b/cmd/crc/cmd/console_test.go index 0910dfb809..1e3e1d90bb 100644 --- a/cmd/crc/cmd/console_test.go +++ b/cmd/crc/cmd/console_test.go @@ -6,6 +6,8 @@ import ( "fmt" "testing" + "github.com/crc-org/crc/v2/pkg/crc/preset" + apiTypes "github.com/crc-org/crc/v2/pkg/crc/api/client" "github.com/crc-org/crc/v2/pkg/crc/daemonclient" "github.com/crc-org/crc/v2/pkg/crc/machine/fakemachine" @@ -15,19 +17,14 @@ import ( "github.com/stretchr/testify/assert" ) -var DummyClusterConfig = types.ClusterConfig{ - ClusterType: "openshift", - ClusterCACert: "MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ", - KubeConfig: "/tmp/kubeconfig", - KubeAdminPass: "foobar", - ClusterAPI: "https://foo.testing:6443", - WebConsoleURL: "https://console.foo.testing:6443", - ProxyConfig: nil, +func setUpClientForConsole(t *testing.T) *daemonclient.Client { + return setUpClientForConsoleWithPreset(t, preset.OpenShift) } -func setUpClientForConsole(t *testing.T) *daemonclient.Client { +func setUpClientForConsoleWithPreset(t *testing.T, preset preset.Preset) *daemonclient.Client { client := mocks.NewClient(t) + DummyClusterConfig := createDummyClusterConfig(preset) client.On("WebconsoleURL").Return( &apiTypes.ConsoleResult{ ClusterConfig: DummyClusterConfig, @@ -38,6 +35,18 @@ func setUpClientForConsole(t *testing.T) *daemonclient.Client { } } +func createDummyClusterConfig(preset preset.Preset) types.ClusterConfig { + return types.ClusterConfig{ + ClusterType: preset, + ClusterCACert: "MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ", + KubeConfig: "/tmp/kubeconfig", + KubeAdminPass: "foobar", + ClusterAPI: "https://foo.testing:6443", + WebConsoleURL: "https://console.foo.testing:6443", + ProxyConfig: nil, + } +} + func setUpFailingClientForConsole(t *testing.T) *daemonclient.Client { client := mocks.NewClient(t) @@ -106,3 +115,12 @@ func TestConsoleJSONError(t *testing.T) { assert.NoError(t, runConsole(out, setUpFailingClientForConsole(t), false, false, jsonFormat)) assert.JSONEq(t, `{"error":"console failed", "success":false}`, out.String()) } + +func TestConsoleThrowsErrorInMicroShiftPreset(t *testing.T) { + // Given + out := new(bytes.Buffer) + // When + err := runConsole(out, setUpClientForConsoleWithPreset(t, preset.Microshift), false, false, "") + // Then + assert.EqualError(t, err, "error : this option is not supported for microshift preset. Please refer to the documentation for a list of supported presets for using this option") +}