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

test(init): override SHELL variable to not depend on local shell #4148

Merged
merged 1 commit into from
Sep 26, 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
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,
}))
}
Loading