Skip to content

Commit 54109c3

Browse files
isolate HOME in tests inheriting parent env
1 parent 73767bd commit 54109c3

7 files changed

Lines changed: 24 additions & 23 deletions

File tree

test/integration/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestConfigFlagOverridesConfigPath(t *testing.T) {
8686
customConfig := filepath.Join(t.TempDir(), "custom.toml")
8787
writeConfigFile(t, customConfig)
8888

89-
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", customConfig, "config", "path")
89+
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", customConfig, "config", "path")
9090
require.NoError(t, err, stderr)
9191
requireExitCode(t, 0, err)
9292

@@ -180,7 +180,7 @@ future_field = "should be ignored"
180180
configFile := filepath.Join(t.TempDir(), "config.toml")
181181
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
182182

183-
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "config", "path")
183+
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "config", "path")
184184
require.NoError(t, err, stderr)
185185
requireExitCode(t, 0, err)
186186
}
@@ -195,7 +195,7 @@ tag = "latest"
195195
configFile := filepath.Join(t.TempDir(), "config.toml")
196196
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
197197

198-
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "stop")
198+
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "stop")
199199
require.Error(t, err)
200200
requireExitCode(t, 1, err)
201201
assert.Contains(t, stderr, "port is required")
@@ -233,7 +233,7 @@ port = "4566"
233233
configFile := filepath.Join(t.TempDir(), "config.toml")
234234
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
235235

236-
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "config", "path")
236+
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "config", "path")
237237
require.NoError(t, err, stderr)
238238
requireExitCode(t, 0, err)
239239
}

test/integration/docs_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package integration_test
22

33
import (
4-
"os"
54
"path/filepath"
65
"testing"
76

@@ -13,7 +12,7 @@ func TestDocsCommandGeneratesManPages(t *testing.T) {
1312
t.Parallel()
1413
dir := filepath.Join(t.TempDir(), "manpages")
1514

16-
_, stderr, err := runLstk(t, testContext(t), "", os.Environ(), "docs", "--format", "man", "--dir", dir)
15+
_, stderr, err := runLstk(t, testContext(t), "", testEnvWithHome(t.TempDir(), ""), "docs", "--format", "man", "--dir", dir)
1716
require.NoError(t, err, stderr)
1817
requireExitCode(t, 0, err)
1918

@@ -26,7 +25,7 @@ func TestDocsCommandGeneratesMarkdown(t *testing.T) {
2625
t.Parallel()
2726
dir := filepath.Join(t.TempDir(), "markdown")
2827

29-
_, stderr, err := runLstk(t, testContext(t), "", os.Environ(), "docs", "--format", "markdown", "--dir", dir)
28+
_, stderr, err := runLstk(t, testContext(t), "", testEnvWithHome(t.TempDir(), ""), "docs", "--format", "markdown", "--dir", dir)
3029
require.NoError(t, err, stderr)
3130
requireExitCode(t, 0, err)
3231

@@ -39,14 +38,14 @@ func TestDocsCommandRejectsInvalidFormat(t *testing.T) {
3938
t.Parallel()
4039
dir := t.TempDir()
4140

42-
_, _, err := runLstk(t, testContext(t), "", os.Environ(), "docs", "--format", "invalid", "--dir", dir)
41+
_, _, err := runLstk(t, testContext(t), "", testEnvWithHome(t.TempDir(), ""), "docs", "--format", "invalid", "--dir", dir)
4342
require.Error(t, err)
4443
requireExitCode(t, 1, err)
4544
}
4645

4746
func TestDocsCommandIsHidden(t *testing.T) {
4847
t.Parallel()
49-
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--help")
48+
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--help")
5049
require.NoError(t, err, stderr)
5150

5251
assert.NotContains(t, stdout, "docs")

test/integration/non_interactive_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
)
1010

1111
func TestNonInteractiveFlagBlocksLogin(t *testing.T) {
12-
out, err := runLstkInPTY(t, testContext(t), nil, "login", "--non-interactive")
12+
t.Parallel()
13+
out, err := runLstkInPTY(t, testContext(t), testEnvWithHome(t.TempDir(), ""), "login", "--non-interactive")
1314
require.Error(t, err, "expected login --non-interactive to fail")
1415
requireExitCode(t, 1, err)
1516
assert.Contains(t, out, "login requires an interactive terminal")

test/integration/status_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestStatusCommandWorksWithNonDefaultPort(t *testing.T) {
114114
configFile := filepath.Join(t.TempDir(), "config.toml")
115115
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
116116

117-
stdout, stderr, err := runLstk(t, ctx, "", nil, "--config", configFile, "status")
117+
stdout, stderr, err := runLstk(t, ctx, "", testEnvWithHome(t.TempDir(), ""), "--config", configFile, "status")
118118
require.NoError(t, err, "lstk status failed: %s", stderr)
119119
assert.Contains(t, stdout, "4.14.1")
120120
}
@@ -163,7 +163,7 @@ func TestStatusCommandForSnowflakeShowsNoResources(t *testing.T) {
163163
ctx := testContext(t)
164164
startTestSnowflakeContainer(t, ctx)
165165

166-
stdout, stderr, err := runLstk(t, ctx, "", nil, "--config", writeSnowflakeConfig(t, "4566"), "status")
166+
stdout, stderr, err := runLstk(t, ctx, "", testEnvWithHome(t.TempDir(), ""), "--config", writeSnowflakeConfig(t, "4566"), "status")
167167
require.NoError(t, err, "lstk status failed for snowflake: %s", stderr)
168168
requireExitCode(t, 0, err)
169169

test/integration/stop_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestStopCommandStopsExternalContainer(t *testing.T) {
6262

6363
startExternalContainer(t, ctx, fakeImage, "localstack-external", "4566")
6464

65-
stdout, stderr, err := runLstk(t, ctx, "", nil, "stop")
65+
stdout, stderr, err := runLstk(t, ctx, "", testEnvWithHome(t.TempDir(), ""), "stop")
6666
require.NoError(t, err, "lstk stop should stop external container: %s", stderr)
6767
requireExitCode(t, 0, err)
6868
assert.Contains(t, stdout, "stopped")
@@ -79,14 +79,15 @@ func TestStopCommandIsIdempotent(t *testing.T) {
7979
ctx := testContext(t)
8080
startTestContainer(t, ctx)
8181

82-
_, stderr, err := runLstk(t, ctx, "", nil, "stop")
82+
e := testEnvWithHome(t.TempDir(), "")
83+
_, stderr, err := runLstk(t, ctx, "", e, "stop")
8384
require.NoError(t, err, "first lstk stop failed: %s", stderr)
8485
requireExitCode(t, 0, err)
8586

8687
_, err = dockerClient.ContainerInspect(ctx, containerName)
8788
require.Error(t, err, "container should not exist after first stop")
8889

89-
_, _, err = runLstk(t, ctx, "", nil, "stop")
90+
_, _, err = runLstk(t, ctx, "", e, "stop")
9091
assert.Error(t, err, "second lstk stop should fail since container already removed")
9192
requireExitCode(t, 1, err)
9293
}

test/integration/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestUpdateCheckCommandNonInteractive(t *testing.T) {
3636
t.Parallel()
3737
ctx := testContext(t)
3838

39-
stdout, stderr, err := runLstk(t, ctx, "", nil, "update", "--check", "--non-interactive")
39+
stdout, stderr, err := runLstk(t, ctx, "", testEnvWithHome(t.TempDir(), ""), "update", "--check", "--non-interactive")
4040
require.NoError(t, err, "lstk update --check --non-interactive failed: %s", stderr)
4141
requireExitCode(t, 0, err)
4242
assert.Contains(t, stdout, "Note:", "should show a note in non-interactive mode")

test/integration/volume_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ volume = "` + escapeTomlPath(customVolume) + `"
4747
configFile := filepath.Join(t.TempDir(), "config.toml")
4848
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
4949

50-
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "volume", "path")
50+
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "volume", "path")
5151
require.NoError(t, err, stderr)
5252
requireExitCode(t, 0, err)
5353

@@ -90,7 +90,7 @@ volume = "` + escapeTomlPath(volumeDir) + `"
9090
configFile := filepath.Join(t.TempDir(), "config.toml")
9191
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
9292

93-
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "--non-interactive", "volume", "clear", "--force")
93+
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "--non-interactive", "volume", "clear", "--force")
9494
require.NoError(t, err, "lstk volume clear failed: %s\nstdout: %s", stderr, stdout)
9595
requireExitCode(t, 0, err)
9696

@@ -135,7 +135,7 @@ volume = "` + escapeTomlPath(volumeDir) + `"
135135
configFile := filepath.Join(t.TempDir(), "config.toml")
136136
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
137137

138-
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "--non-interactive", "volume", "clear", "--force")
138+
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "--non-interactive", "volume", "clear", "--force")
139139
require.NoError(t, err, "lstk volume clear failed: %s\nstdout: %s", stderr, stdout)
140140
requireExitCode(t, 0, err)
141141

@@ -158,13 +158,13 @@ volume = "` + escapeTomlPath(volumeDir) + `"
158158
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
159159

160160
// Wrong type should fail
161-
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "--non-interactive", "volume", "clear", "--force", "--type", "snowflake")
161+
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "--non-interactive", "volume", "clear", "--force", "--type", "snowflake")
162162
require.Error(t, err)
163163
requireExitCode(t, 1, err)
164164
assert.Contains(t, stderr, "not found")
165165

166166
// Correct type should succeed
167-
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "--non-interactive", "volume", "clear", "--force", "--type", "aws")
167+
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "--non-interactive", "volume", "clear", "--force", "--type", "aws")
168168
require.NoError(t, err, "lstk volume clear failed: %s\nstdout: %s", stderr, stdout)
169169
requireExitCode(t, 0, err)
170170

@@ -223,7 +223,7 @@ volume = "` + escapeTomlPath(volumeDir) + `"
223223
configFile := filepath.Join(t.TempDir(), "config.toml")
224224
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
225225

226-
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), os.Environ(), "--config", configFile, "--non-interactive", "volume", "clear", "--force")
226+
_, stderr, err := runLstk(t, testContext(t), t.TempDir(), testEnvWithHome(t.TempDir(), ""), "--config", configFile, "--non-interactive", "volume", "clear", "--force")
227227
if err == nil {
228228
t.Skip("Docker is configured with user namespace remapping; root-owned files cleared without issue")
229229
}
@@ -258,7 +258,7 @@ volume = "` + escapeTomlPath(volumeDir) + `"
258258
startVolumeClear := func(t *testing.T, configFile string) (*os.File, *syncBuffer, chan struct{}, *exec.Cmd) {
259259
t.Helper()
260260
cmd := exec.CommandContext(testContext(t), binaryPath(), "--config", configFile, "volume", "clear")
261-
cmd.Env = os.Environ()
261+
cmd.Env = testEnvWithHome(t.TempDir(), "")
262262
ptmx, err := pty.Start(cmd)
263263
require.NoError(t, err, "failed to start command in PTY")
264264
t.Cleanup(func() { _ = ptmx.Close() })

0 commit comments

Comments
 (0)