Skip to content

Commit 3b3bac6

Browse files
committed
Fix test
1 parent dc702b5 commit 3b3bac6

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

test/integration/emulator_select_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func freshConfigEnv(t *testing.T) (env.Environ, string) {
2626
require.NoError(t, os.MkdirAll(filepath.Join(tmpHome, ".config"), 0755))
2727
return env.Without(env.Home).
2828
With(env.Home, tmpHome).
29-
With("USERPROFILE", tmpHome), tmpHome
29+
With("USERPROFILE", tmpHome).
30+
With(env.Keyring, "file").
31+
With(env.DisableEvents, "1"), tmpHome
3032
}
3133

3234
func TestEmulatorFlagSwitchesConfigToSnowflake(t *testing.T) {
@@ -79,23 +81,25 @@ func TestFirstRunShowsEmulatorSelectionPrompt(t *testing.T) {
7981
close(outputCh)
8082
}()
8183

82-
require.Eventually(t, func() bool {
84+
if !assert.Eventually(t, func() bool {
8385
return bytes.Contains(out.Bytes(), []byte("Which emulator would you like to use?"))
84-
}, 10*time.Second, 100*time.Millisecond, "emulator selection prompt should appear on first run")
86+
}, 100*time.Second, 100*time.Millisecond, "emulator selection prompt should appear on first run") {
87+
t.Logf("process output so far:\n%s", out.String())
88+
t.FailNow()
89+
}
8590

86-
// Choose Snowflake.
87-
_, err = ptmx.Write([]byte("s"))
91+
// Accept the default (AWS) by pressing Enter.
92+
_, err = ptmx.Write([]byte("\r"))
8893
require.NoError(t, err)
8994

90-
require.Eventually(t, func() bool {
91-
return bytes.Contains(out.Bytes(), []byte("Snowflake emulator selected"))
92-
}, 5*time.Second, 100*time.Millisecond, "confirmation should appear after selection")
93-
94-
// Config is written before the confirmation is emitted, so it is safe to read now.
95+
// The config is written inside onSelected, before container.Start is attempted.
96+
// Polling the file directly is more reliable than waiting for the TUI confirmation
97+
// message, which may not render if container.Start fails fast (e.g. license check).
9598
configPath := filepath.Join(tmpHome, ".config", "lstk", "config.toml")
96-
got, err := os.ReadFile(configPath)
97-
require.NoError(t, err, "config file should have been created on first run")
98-
assert.Contains(t, string(got), `type = "snowflake"`)
99+
require.Eventually(t, func() bool {
100+
got, readErr := os.ReadFile(configPath)
101+
return readErr == nil && bytes.Contains(got, []byte(`type = "aws"`))
102+
}, 10*time.Second, 100*time.Millisecond, "config file should be written with aws emulator on first run")
99103

100104
// Kill the process — we do not need the emulator to actually start.
101105
cancel()

0 commit comments

Comments
 (0)