Skip to content

Commit 692ee66

Browse files
authored
test(init): override SHELL variable to not depend on local shell (scaleway#4148)
1 parent aeb2de7 commit 692ee66

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

internal/namespaces/autocomplete/autocomplete.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ func InstallCommandRun(ctx context.Context, argsI interface{}) (i interface{}, e
172172
logger.Debugf("shellArg: %v", shellArg)
173173
if shellArg == "" {
174174
defaultShellName := "bash"
175-
if os.Getenv("SHELL") != "" {
176-
defaultShellName = filepath.Base(os.Getenv("SHELL"))
175+
176+
if core.ExtractEnv(ctx, "SHELL") != "" {
177+
defaultShellName = filepath.Base(core.ExtractEnv(ctx, "SHELL"))
177178
}
178179

179180
promptedShell, err := interactive.PromptStringWithConfig(&interactive.PromptStringConfig{

internal/namespaces/init/init_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,12 @@ func TestInit(t *testing.T) {
226226

227227
func TestInit_Prompt(t *testing.T) {
228228
promptResponse := []string{
229-
"secret-key",
230-
"access-key",
231-
"organization-id",
232-
" ",
229+
"secret-key", // Secret key prompt, should be replaced in BeforeFunc.
230+
"access-key", // Access key prompt, should be replaced in BeforeFunc.
231+
"organization-id", // Organization prompt, should be replaced in BeforeFunc.
232+
" ", // default-project-id list prompt, space is validation, it will pick default organization project.
233+
"", // Telemetry prompt, use default value.
234+
"y", // Autocomplete prompt, enable it but the tests should override a SHELL variable to avoid breaking because of local configuration.
233235
}
234236

235237
t.Run("Simple", core.Test(&core.TestConfig{
@@ -266,6 +268,9 @@ func TestInit_Prompt(t *testing.T) {
266268
assert.Equal(t, *config.DefaultProjectID, *config.DefaultProjectID)
267269
}),
268270
),
271+
OverrideEnv: map[string]string{
272+
"SHELL": "/bin/bash",
273+
},
269274
PromptResponseMocks: promptResponse,
270275
}))
271276
}

0 commit comments

Comments
 (0)