Skip to content

Commit ffe5ca9

Browse files
fix tests using local user config
1 parent 2122f33 commit ffe5ca9

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

test/integration/logs_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package integration_test
22

33
import (
44
"bufio"
5+
"os"
56
"os/exec"
7+
"path/filepath"
68
"strings"
79
"testing"
810
"time"
@@ -13,6 +15,21 @@ import (
1315
"github.com/stretchr/testify/require"
1416
)
1517

18+
// writeAwsConfig writes a minimal aws-only config so tests don't inherit the
19+
// developer's real ~/.config/lstk/config.toml (which may target a different
20+
// emulator / running container).
21+
func writeAwsConfig(t *testing.T) string {
22+
t.Helper()
23+
configFile := filepath.Join(t.TempDir(), "config.toml")
24+
require.NoError(t, os.WriteFile(configFile, []byte(`
25+
[[containers]]
26+
type = "aws"
27+
tag = "latest"
28+
port = "4566"
29+
`), 0644))
30+
return configFile
31+
}
32+
1633
func TestLogsExitsByDefault(t *testing.T) {
1734
requireDocker(t)
1835
cleanup()
@@ -21,8 +38,9 @@ func TestLogsExitsByDefault(t *testing.T) {
2138
ctx := testContext(t)
2239
startTestContainer(t, ctx)
2340

41+
configFile := writeAwsConfig(t)
2442
analyticsSrv, events := mockAnalyticsServer(t)
25-
_, _, err := runLstk(t, ctx, "", env.With(env.AnalyticsEndpoint, analyticsSrv.URL), "logs")
43+
_, _, err := runLstk(t, ctx, "", env.With(env.AnalyticsEndpoint, analyticsSrv.URL), "--config", configFile, "logs")
2644
require.NoError(t, err, "lstk logs should exit cleanly when container is running")
2745
requireExitCode(t, 0, err)
2846
assertCommandTelemetry(t, events, "logs", 0)
@@ -33,8 +51,9 @@ func TestLogsCommandFailsWhenNotRunning(t *testing.T) {
3351
cleanup()
3452
t.Cleanup(cleanup)
3553

54+
configFile := writeAwsConfig(t)
3655
analyticsSrv, events := mockAnalyticsServer(t)
37-
_, stderr, err := runLstk(t, testContext(t), "", env.With(env.AnalyticsEndpoint, analyticsSrv.URL), "logs", "--follow")
56+
_, stderr, err := runLstk(t, testContext(t), "", env.With(env.AnalyticsEndpoint, analyticsSrv.URL), "--config", configFile, "logs", "--follow")
3857
require.Error(t, err, "expected lstk logs --follow to fail when container not running")
3958
requireExitCode(t, 1, err)
4059
assert.Contains(t, stderr, "emulator is not running")
@@ -51,8 +70,9 @@ func TestLogsFollowStreamsOutput(t *testing.T) {
5170

5271
const marker = "lstk-logs-test-marker"
5372

73+
configFile := writeAwsConfig(t)
5474
// Uses StdoutPipe for streaming — cannot use runLstk.
55-
logsCmd := exec.CommandContext(ctx, binaryPath(), "logs", "--follow")
75+
logsCmd := exec.CommandContext(ctx, binaryPath(), "--config", configFile, "logs", "--follow")
5676
stdout, err := logsCmd.StdoutPipe()
5777
require.NoError(t, err, "failed to get stdout pipe")
5878

0 commit comments

Comments
 (0)