From 692ee6685d9a109de8aaf10a2e9cc44e9aeb3819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jules=20Cast=C3=A9ran?= Date: Thu, 26 Sep 2024 19:09:29 +0200 Subject: [PATCH] test(init): override SHELL variable to not depend on local shell (#4148) --- internal/namespaces/autocomplete/autocomplete.go | 5 +++-- internal/namespaces/init/init_test.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/namespaces/autocomplete/autocomplete.go b/internal/namespaces/autocomplete/autocomplete.go index b8c61a41ff..5542078a1a 100644 --- a/internal/namespaces/autocomplete/autocomplete.go +++ b/internal/namespaces/autocomplete/autocomplete.go @@ -172,8 +172,9 @@ func InstallCommandRun(ctx context.Context, argsI interface{}) (i interface{}, e logger.Debugf("shellArg: %v", shellArg) if shellArg == "" { defaultShellName := "bash" - if os.Getenv("SHELL") != "" { - defaultShellName = filepath.Base(os.Getenv("SHELL")) + + if core.ExtractEnv(ctx, "SHELL") != "" { + defaultShellName = filepath.Base(core.ExtractEnv(ctx, "SHELL")) } promptedShell, err := interactive.PromptStringWithConfig(&interactive.PromptStringConfig{ diff --git a/internal/namespaces/init/init_test.go b/internal/namespaces/init/init_test.go index e4b2da4fc9..ed79ce65c3 100644 --- a/internal/namespaces/init/init_test.go +++ b/internal/namespaces/init/init_test.go @@ -226,10 +226,12 @@ func TestInit(t *testing.T) { func TestInit_Prompt(t *testing.T) { promptResponse := []string{ - "secret-key", - "access-key", - "organization-id", - " ", + "secret-key", // Secret key prompt, should be replaced in BeforeFunc. + "access-key", // Access key prompt, should be replaced in BeforeFunc. + "organization-id", // Organization prompt, should be replaced in BeforeFunc. + " ", // default-project-id list prompt, space is validation, it will pick default organization project. + "", // Telemetry prompt, use default value. + "y", // Autocomplete prompt, enable it but the tests should override a SHELL variable to avoid breaking because of local configuration. } t.Run("Simple", core.Test(&core.TestConfig{ @@ -266,6 +268,9 @@ func TestInit_Prompt(t *testing.T) { assert.Equal(t, *config.DefaultProjectID, *config.DefaultProjectID) }), ), + OverrideEnv: map[string]string{ + "SHELL": "/bin/bash", + }, PromptResponseMocks: promptResponse, })) }