Skip to content

Commit

Permalink
test(init): override SHELL variable to not depend on local shell (#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored Sep 26, 2024
1 parent aeb2de7 commit 692ee66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions internal/namespaces/autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
13 changes: 9 additions & 4 deletions internal/namespaces/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}))
}

0 comments on commit 692ee66

Please sign in to comment.