Skip to content

Commit 86c9ca5

Browse files
committed
Fix remaining e2e review feedback
1 parent aaf06f4 commit 86c9ca5

5 files changed

Lines changed: 45 additions & 17 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test-unit: check-toolchain
9696
e2e: build
9797
@if [ -z "$$FIZZY_TEST_TOKEN" ]; then echo "Error: FIZZY_TEST_TOKEN not set"; exit 1; fi
9898
@if [ -z "$$FIZZY_TEST_ACCOUNT" ]; then echo "Error: FIZZY_TEST_ACCOUNT not set"; exit 1; fi
99-
go test -v -timeout 10m ./e2e/cli_tests/...
99+
go test -v -count=1 -timeout 10m ./e2e/cli_tests/...
100100

101101
test-e2e: e2e
102102

@@ -108,7 +108,7 @@ e2e-file: build
108108
@if [ -z "$(FILE)" ]; then echo "Usage: make e2e-file FILE=crud_board"; exit 1; fi
109109
@if [ -z "$$FIZZY_TEST_TOKEN" ]; then echo "Error: FIZZY_TEST_TOKEN not set"; exit 1; fi
110110
@if [ -z "$$FIZZY_TEST_ACCOUNT" ]; then echo "Error: FIZZY_TEST_ACCOUNT not set"; exit 1; fi
111-
go test -v ./e2e/cli_tests/$(FILE)_test.go
111+
go test -v -count=1 ./e2e/cli_tests/$(FILE)_test.go
112112

113113
test-file: e2e-file
114114

@@ -117,7 +117,7 @@ e2e-run: build
117117
@if [ -z "$(NAME)" ]; then echo "Usage: make e2e-run NAME=TestBoardList"; exit 1; fi
118118
@if [ -z "$$FIZZY_TEST_TOKEN" ]; then echo "Error: FIZZY_TEST_TOKEN not set"; exit 1; fi
119119
@if [ -z "$$FIZZY_TEST_ACCOUNT" ]; then echo "Error: FIZZY_TEST_ACCOUNT not set"; exit 1; fi
120-
go test -v -run $(NAME) ./e2e/cli_tests/...
120+
go test -v -count=1 -run $(NAME) ./e2e/cli_tests/...
121121

122122
test-run: e2e-run
123123

e2e/cli_tests/main_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,45 @@ var (
2828
)
2929

3030
func TestMain(m *testing.M) {
31+
os.Exit(runMain(m))
32+
}
33+
34+
func runMain(m *testing.M) int {
3135
cfg = harness.LoadConfig()
3236
if missing := cfg.MissingVars(); len(missing) > 0 {
3337
fmt.Fprintf(os.Stderr, "Skipping CLI e2e tests — missing env vars: %v\n", missing)
3438
fmt.Fprintln(os.Stderr, "Set FIZZY_TEST_TOKEN and FIZZY_TEST_ACCOUNT to run these tests.")
35-
os.Exit(0)
39+
return 0
3640
}
3741

3842
if !fileExists(cfg.BinaryPath) {
3943
repoRoot, err := harness.RepoRoot()
4044
if err != nil {
4145
fmt.Fprintln(os.Stderr, err.Error())
42-
os.Exit(1)
46+
return 1
4347
}
4448
tmpDir, err := os.MkdirTemp("", "fizzy-e2e-cli-build-*")
4549
if err != nil {
4650
fmt.Fprintln(os.Stderr, err.Error())
47-
os.Exit(1)
51+
return 1
4852
}
53+
defer os.RemoveAll(tmpDir)
4954
binPath := filepath.Join(tmpDir, "fizzy")
5055
cmd := exec.Command("go", "build", "-o", binPath, "./cmd/fizzy")
5156
cmd.Dir = repoRoot
5257
if out, err := cmd.CombinedOutput(); err != nil {
53-
_ = os.RemoveAll(tmpDir)
5458
fmt.Fprintf(os.Stderr, "failed to build binary: %v\n%s\n", err, string(out))
55-
os.Exit(1)
59+
return 1
5660
}
5761
_ = os.Setenv("FIZZY_TEST_BINARY", binPath)
5862
cfg.BinaryPath = binPath
59-
defer os.RemoveAll(tmpDir)
6063
}
6164

6265
var err error
6366
fixture, err = harness.NewSharedFixture(cfg)
6467
if err != nil {
6568
fmt.Fprintf(os.Stderr, "fixture setup failed: %v\n", err)
66-
os.Exit(1)
69+
return 1
6770
}
6871
printFixtureInfo()
6972

@@ -72,7 +75,7 @@ func TestMain(m *testing.M) {
7275
if os.Getenv("FIZZY_E2E_KEEP_FIXTURE") == "1" {
7376
fmt.Fprintln(os.Stderr, "Keeping CLI e2e fixture (FIZZY_E2E_KEEP_FIXTURE=1)")
7477
printFixtureInfo()
75-
os.Exit(code)
78+
return code
7679
}
7780
if delay := teardownDelay(); delay > 0 {
7881
fmt.Fprintf(os.Stderr, "Delaying CLI e2e fixture teardown for %s\n", delay)
@@ -82,7 +85,7 @@ func TestMain(m *testing.M) {
8285
if err := fixture.Teardown(); err != nil {
8386
fmt.Fprintf(os.Stderr, "warning: fixture teardown error: %v\n", err)
8487
}
85-
os.Exit(code)
88+
return code
8689
}
8790

8891
func printFixtureInfo() {

e2e/cli_tests/search_and_auth_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ func TestAuthMissingToken(t *testing.T) {
2424
missingCfg := *cfg
2525
missingCfg.Token = ""
2626
h := harness.NewWithConfig(t, &missingCfg)
27-
assertResult(t, h.Run("board", "list"), harness.ExitAuthFailure)
27+
assertResult(t, h.RunWithEnv(map[string]string{
28+
"FIZZY_TOKEN": "",
29+
"FIZZY_ACCOUNT": "",
30+
}, "board", "list"), harness.ExitAuthFailure)
2831
}

e2e/harness/harness.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ func (h *Harness) RunWithoutAuth(args ...string) *Result {
247247

248248
// buildArgs builds the full argument list with global options.
249249
func (h *Harness) buildArgs(args ...string) []string {
250-
globalArgs := []string{
251-
"--token", h.Token,
252-
"--api-url", h.APIURL,
250+
globalArgs := []string{"--api-url", h.APIURL}
251+
if h.Token != "" {
252+
globalArgs = append(globalArgs, "--token", h.Token)
253253
}
254254
// Append global args after the command args
255255
return append(args, globalArgs...)
@@ -260,8 +260,13 @@ func (h *Harness) buildArgs(args ...string) []string {
260260
func (h *Harness) globalEnv() map[string]string {
261261
return map[string]string{
262262
"FIZZY_PROFILE": h.Account,
263+
"FIZZY_ACCOUNT": "",
264+
"FIZZY_TOKEN": "",
263265
"FIZZY_NO_KEYRING": "1",
264266
"HOME": h.configHome,
267+
"XDG_CONFIG_HOME": filepath.Join(h.configHome, "config"),
268+
"XDG_DATA_HOME": filepath.Join(h.configHome, "data"),
269+
"XDG_STATE_HOME": filepath.Join(h.configHome, "state"),
265270
}
266271
}
267272

e2e/harness/runner.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"os"
77
"os/exec"
8+
"strings"
89
"syscall"
910
)
1011

@@ -17,7 +18,23 @@ func Execute(binaryPath string, args []string, env map[string]string) *Result {
1718
cmd.Stderr = &stderr
1819

1920
// Set up environment
20-
cmd.Env = os.Environ()
21+
baseEnv := os.Environ()
22+
if len(env) > 0 {
23+
overrides := make(map[string]struct{}, len(env))
24+
for k := range env {
25+
overrides[k] = struct{}{}
26+
}
27+
filtered := baseEnv[:0]
28+
for _, entry := range baseEnv {
29+
key, _, _ := strings.Cut(entry, "=")
30+
if _, ok := overrides[key]; ok {
31+
continue
32+
}
33+
filtered = append(filtered, entry)
34+
}
35+
baseEnv = filtered
36+
}
37+
cmd.Env = append([]string(nil), baseEnv...)
2138
for k, v := range env {
2239
cmd.Env = append(cmd.Env, k+"="+v)
2340
}

0 commit comments

Comments
 (0)