Skip to content

Commit a663379

Browse files
committed
Fix follow-up e2e review issues
1 parent 724daca commit a663379

5 files changed

Lines changed: 68 additions & 29 deletions

File tree

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
surface-snapshot surface-check lint-actions
55

66
BINARY := $(CURDIR)/bin/fizzy
7+
FIZZY_TEST_BINARY ?= $(BINARY)
78

89
# Load local test credentials if present, but refuse tracked local secret files.
910
ifneq ($(shell git ls-files --error-unmatch .env.test >/dev/null 2>&1 && echo tracked),)
1011
$(error .env.test is tracked by Git. Remove it from version control and keep local secret files untracked)
1112
endif
1213
-include .env.test
13-
export FIZZY_TEST_TOKEN FIZZY_TEST_ACCOUNT FIZZY_TEST_API_URL
14+
export FIZZY_TEST_TOKEN FIZZY_TEST_ACCOUNT FIZZY_TEST_API_URL FIZZY_TEST_BINARY
1415
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
1516
LDFLAGS := -X main.version=$(VERSION)
1617

@@ -95,7 +96,7 @@ test-unit: check-toolchain
9596
e2e: build
9697
@if [ -z "$$FIZZY_TEST_TOKEN" ]; then echo "Error: FIZZY_TEST_TOKEN not set"; exit 1; fi
9798
@if [ -z "$$FIZZY_TEST_ACCOUNT" ]; then echo "Error: FIZZY_TEST_ACCOUNT not set"; exit 1; fi
98-
FIZZY_TEST_BINARY=$(BINARY) go test -v -timeout 10m ./e2e/cli_tests/...
99+
go test -v -timeout 10m ./e2e/cli_tests/...
99100

100101
test-e2e: e2e
101102

@@ -107,7 +108,7 @@ e2e-file: build
107108
@if [ -z "$(FILE)" ]; then echo "Usage: make e2e-file FILE=crud_board"; exit 1; fi
108109
@if [ -z "$$FIZZY_TEST_TOKEN" ]; then echo "Error: FIZZY_TEST_TOKEN not set"; exit 1; fi
109110
@if [ -z "$$FIZZY_TEST_ACCOUNT" ]; then echo "Error: FIZZY_TEST_ACCOUNT not set"; exit 1; fi
110-
FIZZY_TEST_BINARY=$(BINARY) go test -v ./e2e/cli_tests/$(FILE)_test.go
111+
go test -v ./e2e/cli_tests/$(FILE)_test.go
111112

112113
test-file: e2e-file
113114

@@ -116,7 +117,7 @@ e2e-run: build
116117
@if [ -z "$(NAME)" ]; then echo "Usage: make e2e-run NAME=TestBoardList"; exit 1; fi
117118
@if [ -z "$$FIZZY_TEST_TOKEN" ]; then echo "Error: FIZZY_TEST_TOKEN not set"; exit 1; fi
118119
@if [ -z "$$FIZZY_TEST_ACCOUNT" ]; then echo "Error: FIZZY_TEST_ACCOUNT not set"; exit 1; fi
119-
FIZZY_TEST_BINARY=$(BINARY) go test -v -run $(NAME) ./e2e/cli_tests/...
120+
go test -v -run $(NAME) ./e2e/cli_tests/...
120121

121122
test-run: e2e-run
122123

e2e/cli_tests/crud_subresources_test.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,53 +106,59 @@ func TestStepCRUD(t *testing.T) {
106106
func TestReactionCRUD(t *testing.T) {
107107
h := newHarness(t)
108108
cardStr := strconv.Itoa(fixture.CardNumber)
109-
assertOK(t, h.Run("reaction", "list", "--card", cardStr))
110-
assertOK(t, h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID))
109+
cardReactionsBefore := h.Run("reaction", "list", "--card", cardStr)
110+
assertOK(t, cardReactionsBefore)
111+
commentReactionsBefore := h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID)
112+
assertOK(t, commentReactionsBefore)
111113

112114
cardReaction := h.Run("reaction", "create", "--card", cardStr, "--content", "+1")
113115
assertOK(t, cardReaction)
114-
cardReactionID := cardReaction.GetIDFromLocation()
115-
if cardReactionID == "" {
116-
cardReactionID = cardReaction.GetDataString("id")
117-
}
118-
if cardReactionID == "" {
119-
t.Fatal("no reaction ID in create response")
120-
}
121-
t.Cleanup(func() { newHarness(t).Run("reaction", "delete", cardReactionID, "--card", cardStr) })
122116
cardReactions := h.Run("reaction", "list", "--card", cardStr)
123117
assertOK(t, cardReactions)
118+
cardReactionID := listAddedID(cardReactionsBefore.GetDataArray(), cardReactions.GetDataArray())
119+
if cardReactionID == "" {
120+
t.Fatal("expected created card reaction to appear in list")
121+
}
122+
t.Cleanup(func() {
123+
if cardReactionID != "" {
124+
newHarness(t).Run("reaction", "delete", cardReactionID, "--card", cardStr)
125+
}
126+
})
124127
if listMapByID(cardReactions.GetDataArray(), cardReactionID) == nil {
125128
t.Fatalf("expected card reaction list to include %q", cardReactionID)
126129
}
130+
deletedCardReactionID := cardReactionID
127131
assertOK(t, h.Run("reaction", "delete", cardReactionID, "--card", cardStr))
132+
cardReactionID = ""
128133
cardReactions = h.Run("reaction", "list", "--card", cardStr)
129134
assertOK(t, cardReactions)
130-
if listMapByID(cardReactions.GetDataArray(), cardReactionID) != nil {
131-
t.Fatalf("expected deleted card reaction %q to be absent from list", cardReactionID)
135+
if listMapByID(cardReactions.GetDataArray(), deletedCardReactionID) != nil {
136+
t.Fatalf("expected deleted card reaction %q to be absent from list", deletedCardReactionID)
132137
}
133138

134139
commentReaction := h.Run("reaction", "create", "--card", cardStr, "--comment", fixture.CommentID, "--content", "heart")
135140
assertOK(t, commentReaction)
136-
commentReactionID := commentReaction.GetIDFromLocation()
137-
if commentReactionID == "" {
138-
commentReactionID = commentReaction.GetDataString("id")
139-
}
141+
commentReactions := h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID)
142+
assertOK(t, commentReactions)
143+
commentReactionID := listAddedID(commentReactionsBefore.GetDataArray(), commentReactions.GetDataArray())
140144
if commentReactionID == "" {
141-
t.Fatal("no comment reaction ID in create response")
145+
t.Fatal("expected created comment reaction to appear in list")
142146
}
143147
t.Cleanup(func() {
144-
newHarness(t).Run("reaction", "delete", commentReactionID, "--card", cardStr, "--comment", fixture.CommentID)
148+
if commentReactionID != "" {
149+
newHarness(t).Run("reaction", "delete", commentReactionID, "--card", cardStr, "--comment", fixture.CommentID)
150+
}
145151
})
146-
commentReactions := h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID)
147-
assertOK(t, commentReactions)
148152
if listMapByID(commentReactions.GetDataArray(), commentReactionID) == nil {
149153
t.Fatalf("expected comment reaction list to include %q", commentReactionID)
150154
}
155+
deletedCommentReactionID := commentReactionID
151156
assertOK(t, h.Run("reaction", "delete", commentReactionID, "--card", cardStr, "--comment", fixture.CommentID))
157+
commentReactionID = ""
152158
commentReactions = h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID)
153159
assertOK(t, commentReactions)
154-
if listMapByID(commentReactions.GetDataArray(), commentReactionID) != nil {
155-
t.Fatalf("expected deleted comment reaction %q to be absent from list", commentReactionID)
160+
if listMapByID(commentReactions.GetDataArray(), deletedCommentReactionID) != nil {
161+
t.Fatalf("expected deleted comment reaction %q to be absent from list", deletedCommentReactionID)
156162
}
157163
}
158164

e2e/cli_tests/helpers_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,33 @@ func listIndexByID(items []any, id string) int {
189189
return -1
190190
}
191191

192+
func listAddedID(before, after []any) string {
193+
seen := make(map[string]struct{}, len(before))
194+
for _, item := range before {
195+
m := asMap(item)
196+
if m == nil {
197+
continue
198+
}
199+
if id := mapValueString(m, "id"); id != "" {
200+
seen[id] = struct{}{}
201+
}
202+
}
203+
for _, item := range after {
204+
m := asMap(item)
205+
if m == nil {
206+
continue
207+
}
208+
id := mapValueString(m, "id")
209+
if id == "" {
210+
continue
211+
}
212+
if _, ok := seen[id]; !ok {
213+
return id
214+
}
215+
}
216+
return ""
217+
}
218+
192219
func bodyPlainText(m map[string]any) string {
193220
if m == nil {
194221
return ""

e2e/cli_tests/output_contract_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ func assertNonJSON(t *testing.T, stdout, flag string) {
4848
if s == "" {
4949
t.Fatalf("--%s: produced empty output", flag)
5050
}
51-
if strings.HasPrefix(s, `{"ok"`) {
52-
t.Fatalf("--%s: output looks like a JSON envelope", flag)
51+
var obj map[string]any
52+
if err := json.Unmarshal([]byte(s), &obj); err == nil {
53+
if _, hasOK := obj["ok"]; hasOK {
54+
t.Fatalf("--%s: output looks like a JSON envelope", flag)
55+
}
5356
}
5457
}
5558

e2e/harness/fixture.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ func NewSharedFixture(cfg *Config) (*SharedFixture, error) {
4242
}
4343
f := &SharedFixture{cfg: cfg, configHome: tmpDir}
4444
if err := f.setup(); err != nil {
45-
_ = os.RemoveAll(tmpDir)
45+
if teardownErr := f.Teardown(); teardownErr != nil {
46+
return nil, fmt.Errorf("%w\ncleanup: %v", err, teardownErr)
47+
}
4648
return nil, err
4749
}
4850
return f, nil

0 commit comments

Comments
 (0)