Skip to content

Commit 2771769

Browse files
koki-developclaude
andcommitted
refactor: nest E2E test output fields under body key
Separate HTTP status code from response body assertions by introducing a `body` level in the test output structure, preparing for explicit HTTP status code validation independent of response content. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8bc0916 commit 2771769

16 files changed

Lines changed: 521 additions & 458 deletions

e2e/e2e_test.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ type testInput struct {
4444
}
4545

4646
type testOutput struct {
47-
Status int `yaml:"status"`
47+
Status int `yaml:"status"`
48+
Body testOutputBody `yaml:"body"`
49+
}
50+
51+
type testOutputBody struct {
4852
Compile *runOutput `yaml:"compile"`
4953
Run *runOutput `yaml:"run"`
5054
Error string `yaml:"error"`
@@ -145,39 +149,39 @@ func TestE2E(t *testing.T) {
145149

146150
require.Equal(t, tc.Output.Status, resp.StatusCode, "unexpected HTTP status code")
147151

148-
if tc.Output.Error != "" {
152+
if tc.Output.Body.Error != "" {
149153
var errResp apiErrorResponse
150154
err = json.NewDecoder(resp.Body).Decode(&errResp)
151155
require.NoError(t, err, "failed to decode error response body")
152156

153-
assert.Equal(t, tc.Output.Error, errResp.Error, "error message mismatch")
157+
assert.Equal(t, tc.Output.Body.Error, errResp.Error, "error message mismatch")
154158
} else {
155159
var apiResp apiResponse
156160
err = json.NewDecoder(resp.Body).Decode(&apiResp)
157161
require.NoError(t, err, "failed to decode response body")
158162

159-
if tc.Output.Compile == nil {
163+
if tc.Output.Body.Compile == nil {
160164
assert.Nil(t, apiResp.Compile, "compile should be null")
161165
} else {
162166
require.NotNil(t, apiResp.Compile, "compile should not be null")
163-
assert.Equal(t, tc.Output.Compile.Stdout, decodeBase64(t, apiResp.Compile.Stdout, "compile stdout"), "compile stdout mismatch")
164-
assert.Equal(t, tc.Output.Compile.Stderr, decodeBase64(t, apiResp.Compile.Stderr, "compile stderr"), "compile stderr mismatch")
165-
assert.Equal(t, tc.Output.Compile.Output, decodeBase64(t, apiResp.Compile.Output, "compile output"), "compile output mismatch")
166-
assert.Equal(t, tc.Output.Compile.ExitCode, apiResp.Compile.ExitCode, "compile exit_code mismatch")
167-
assert.Equal(t, tc.Output.Compile.Status, apiResp.Compile.Status, "compile status mismatch")
168-
assert.Equal(t, tc.Output.Compile.Signal, apiResp.Compile.Signal, "compile signal mismatch")
167+
assert.Equal(t, tc.Output.Body.Compile.Stdout, decodeBase64(t, apiResp.Compile.Stdout, "compile stdout"), "compile stdout mismatch")
168+
assert.Equal(t, tc.Output.Body.Compile.Stderr, decodeBase64(t, apiResp.Compile.Stderr, "compile stderr"), "compile stderr mismatch")
169+
assert.Equal(t, tc.Output.Body.Compile.Output, decodeBase64(t, apiResp.Compile.Output, "compile output"), "compile output mismatch")
170+
assert.Equal(t, tc.Output.Body.Compile.ExitCode, apiResp.Compile.ExitCode, "compile exit_code mismatch")
171+
assert.Equal(t, tc.Output.Body.Compile.Status, apiResp.Compile.Status, "compile status mismatch")
172+
assert.Equal(t, tc.Output.Body.Compile.Signal, apiResp.Compile.Signal, "compile signal mismatch")
169173
}
170174

171-
if tc.Output.Run == nil {
175+
if tc.Output.Body.Run == nil {
172176
assert.Nil(t, apiResp.Run, "run should be null")
173177
} else {
174178
require.NotNil(t, apiResp.Run, "run should not be null")
175-
assert.Equal(t, tc.Output.Run.Stdout, decodeBase64(t, apiResp.Run.Stdout, "run stdout"), "run stdout mismatch")
176-
assert.Equal(t, tc.Output.Run.Stderr, decodeBase64(t, apiResp.Run.Stderr, "run stderr"), "run stderr mismatch")
177-
assert.Equal(t, tc.Output.Run.Output, decodeBase64(t, apiResp.Run.Output, "run output"), "run output mismatch")
178-
assert.Equal(t, tc.Output.Run.ExitCode, apiResp.Run.ExitCode, "run exit_code mismatch")
179-
assert.Equal(t, tc.Output.Run.Status, apiResp.Run.Status, "run status mismatch")
180-
assert.Equal(t, tc.Output.Run.Signal, apiResp.Run.Signal, "run signal mismatch")
179+
assert.Equal(t, tc.Output.Body.Run.Stdout, decodeBase64(t, apiResp.Run.Stdout, "run stdout"), "run stdout mismatch")
180+
assert.Equal(t, tc.Output.Body.Run.Stderr, decodeBase64(t, apiResp.Run.Stderr, "run stderr"), "run stderr mismatch")
181+
assert.Equal(t, tc.Output.Body.Run.Output, decodeBase64(t, apiResp.Run.Output, "run output"), "run output mismatch")
182+
assert.Equal(t, tc.Output.Body.Run.ExitCode, apiResp.Run.ExitCode, "run exit_code mismatch")
183+
assert.Equal(t, tc.Output.Body.Run.Status, apiResp.Run.Status, "run status mismatch")
184+
assert.Equal(t, tc.Output.Body.Run.Signal, apiResp.Run.Signal, "run signal mismatch")
181185
}
182186
}
183187
})

e2e/tests/runtime/go.yml

Lines changed: 91 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ tests:
1414
}
1515
output:
1616
status: 200
17-
compile:
18-
stdout: ""
19-
stderr: ""
20-
output: ""
21-
exit_code: 0
22-
status: "OK"
23-
signal: null
24-
run:
25-
stdout: "Hello, World!\n"
26-
stderr: ""
27-
output: "Hello, World!\n"
28-
exit_code: 0
29-
status: "OK"
30-
signal: null
17+
body:
18+
compile:
19+
stdout: ""
20+
stderr: ""
21+
output: ""
22+
exit_code: 0
23+
status: "OK"
24+
signal: null
25+
run:
26+
stdout: "Hello, World!\n"
27+
stderr: ""
28+
output: "Hello, World!\n"
29+
exit_code: 0
30+
status: "OK"
31+
signal: null
3132

3233
- name: "compile error"
3334
input:
@@ -42,13 +43,14 @@ tests:
4243
}
4344
output:
4445
status: 200
45-
compile:
46-
stdout: ""
47-
stderr: "# sandbox\n./main.go:4:5: undefined: undefined_variable\n"
48-
output: "# sandbox\n./main.go:4:5: undefined: undefined_variable\n"
49-
exit_code: 1
50-
status: "OK"
51-
signal: null
46+
body:
47+
compile:
48+
stdout: ""
49+
stderr: "# sandbox\n./main.go:4:5: undefined: undefined_variable\n"
50+
output: "# sandbox\n./main.go:4:5: undefined: undefined_variable\n"
51+
exit_code: 1
52+
status: "OK"
53+
signal: null
5254

5355
- name: "stderr output"
5456
input:
@@ -68,20 +70,21 @@ tests:
6870
}
6971
output:
7072
status: 200
71-
compile:
72-
stdout: ""
73-
stderr: ""
74-
output: ""
75-
exit_code: 0
76-
status: "OK"
77-
signal: null
78-
run:
79-
stdout: ""
80-
stderr: "error message\n"
81-
output: "error message\n"
82-
exit_code: 0
83-
status: "OK"
84-
signal: null
73+
body:
74+
compile:
75+
stdout: ""
76+
stderr: ""
77+
output: ""
78+
exit_code: 0
79+
status: "OK"
80+
signal: null
81+
run:
82+
stdout: ""
83+
stderr: "error message\n"
84+
output: "error message\n"
85+
exit_code: 0
86+
status: "OK"
87+
signal: null
8588

8689
- name: "non-zero exit code"
8790
input:
@@ -98,20 +101,21 @@ tests:
98101
}
99102
output:
100103
status: 200
101-
compile:
102-
stdout: ""
103-
stderr: ""
104-
output: ""
105-
exit_code: 0
106-
status: "OK"
107-
signal: null
108-
run:
109-
stdout: ""
110-
stderr: ""
111-
output: ""
112-
exit_code: 1
113-
status: "OK"
114-
signal: null
104+
body:
105+
compile:
106+
stdout: ""
107+
stderr: ""
108+
output: ""
109+
exit_code: 0
110+
status: "OK"
111+
signal: null
112+
run:
113+
stdout: ""
114+
stderr: ""
115+
output: ""
116+
exit_code: 1
117+
status: "OK"
118+
signal: null
115119

116120
- name: "stderr with non-zero exit code"
117121
input:
@@ -132,20 +136,21 @@ tests:
132136
}
133137
output:
134138
status: 200
135-
compile:
136-
stdout: ""
137-
stderr: ""
138-
output: ""
139-
exit_code: 0
140-
status: "OK"
141-
signal: null
142-
run:
143-
stdout: ""
144-
stderr: "error occurred\n"
145-
output: "error occurred\n"
146-
exit_code: 2
147-
status: "OK"
148-
signal: null
139+
body:
140+
compile:
141+
stdout: ""
142+
stderr: ""
143+
output: ""
144+
exit_code: 0
145+
status: "OK"
146+
signal: null
147+
run:
148+
stdout: ""
149+
stderr: "error occurred\n"
150+
output: "error occurred\n"
151+
exit_code: 2
152+
status: "OK"
153+
signal: null
149154

150155
- name: "pre-installed package golang.org/x/text"
151156
input:
@@ -168,20 +173,21 @@ tests:
168173
}
169174
output:
170175
status: 200
171-
compile:
172-
stdout: ""
173-
stderr: ""
174-
output: ""
175-
exit_code: 0
176-
status: "OK"
177-
signal: null
178-
run:
179-
stdout: "Hello World\n"
180-
stderr: ""
181-
output: "Hello World\n"
182-
exit_code: 0
183-
status: "OK"
184-
signal: null
176+
body:
177+
compile:
178+
stdout: ""
179+
stderr: ""
180+
output: ""
181+
exit_code: 0
182+
status: "OK"
183+
signal: null
184+
run:
185+
stdout: "Hello World\n"
186+
stderr: ""
187+
output: "Hello World\n"
188+
exit_code: 0
189+
status: "OK"
190+
signal: null
185191

186192
- name: "restricted file go.mod rejected"
187193
input:
@@ -194,7 +200,8 @@ tests:
194200
go 1.26
195201
output:
196202
status: 400
197-
error: 'file "go.mod" is not allowed for the go runtime'
203+
body:
204+
error: 'file "go.mod" is not allowed for the go runtime'
198205

199206
- name: "restricted file go.sum rejected"
200207
input:
@@ -204,7 +211,8 @@ tests:
204211
content: ""
205212
output:
206213
status: 400
207-
error: 'file "go.sum" is not allowed for the go runtime'
214+
body:
215+
error: 'file "go.sum" is not allowed for the go runtime'
208216

209217
- name: "restricted file go.mod rejected even with valid main.go"
210218
input:
@@ -222,7 +230,8 @@ tests:
222230
go 1.26
223231
output:
224232
status: 400
225-
error: 'file "go.mod" is not allowed for the go runtime'
233+
body:
234+
error: 'file "go.mod" is not allowed for the go runtime'
226235

227236
- name: "restricted file main rejected"
228237
input:
@@ -237,4 +246,5 @@ tests:
237246
content: "data"
238247
output:
239248
status: 400
240-
error: 'file "main" is not allowed for the go runtime'
249+
body:
250+
error: 'file "main" is not allowed for the go runtime'

0 commit comments

Comments
 (0)