Skip to content

Commit 9e85eca

Browse files
committed
test(gateapi): gateapi generated code expects JSON header to be sent
1 parent b395bc1 commit 9e85eca

File tree

9 files changed

+17
-0
lines changed

9 files changed

+17
-0
lines changed

cmd/account/get_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func TestAccountGet_fail(t *testing.T) {
142142
func testGateAccountGetSuccess() *httptest.Server {
143143
mux := util.TestGateMuxWithVersionHandler()
144144
mux.Handle("/credentials/"+ACCOUNT, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
145+
w.Header().Add("content-type", "application/json")
145146
fmt.Fprintln(w, strings.TrimSpace(accountJson))
146147
}))
147148
return httptest.NewServer(mux)

cmd/account/list_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func TestAccountList_fail(t *testing.T) {
7474
func testGateAccountListSuccess() *httptest.Server {
7575
mux := util.TestGateMuxWithVersionHandler()
7676
mux.Handle("/credentials/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
77+
w.Header().Add("content-type", "application/json")
7778
fmt.Fprintln(w, strings.TrimSpace(accountListJson))
7879
}))
7980
return httptest.NewServer(mux)

cmd/application/delete_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,23 @@ func testGateApplicationDeleteSuccess() *httptest.Server {
7878
mux.Handle("/applications/"+APP, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7979
payload := map[string]string{} // We don't use the payload, we are just checking if the target app exists.
8080
b, _ := json.Marshal(&payload)
81+
w.Header().Add("content-type", "application/json")
8182
fmt.Fprintln(w, string(b))
8283
}))
8384
mux.Handle("/tasks", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
8485
payload := map[string]string{
8586
"ref": "/tasks/id",
8687
}
8788
b, _ := json.Marshal(&payload)
89+
w.Header().Add("content-type", "application/json")
8890
fmt.Fprintln(w, string(b))
8991
}))
9092
mux.Handle("/tasks/id", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
9193
payload := map[string]string{
9294
"status": "SUCCEEDED",
9395
}
9496
b, _ := json.Marshal(&payload)
97+
w.Header().Add("content-type", "application/json")
9598
fmt.Fprintln(w, string(b))
9699
}))
97100
return httptest.NewServer(mux)

cmd/canary/canary-config/get_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func testGateCanaryConfigGetSuccess() *httptest.Server {
157157
mux.Handle(
158158
"/v2/canaryConfig/",
159159
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
160+
w.Header().Add("content-type", "application/json")
160161
fmt.Fprintln(w, strings.TrimSpace(canaryConfigGetJson))
161162
}))
162163
return httptest.NewServer(mux)

cmd/canary/canary-config/list_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func testGateCanaryConfigListSuccess() *httptest.Server {
8585
mux.Handle(
8686
"/v2/canaryConfig",
8787
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
88+
w.Header().Add("content-type", "application/json")
8889
fmt.Fprintln(w, strings.TrimSpace(canaryConfigListJson))
8990
}))
9091
return httptest.NewServer(mux)
@@ -96,6 +97,7 @@ func testGateCanaryConfigListMalformed() *httptest.Server {
9697
mux.Handle(
9798
"/v2/canaryConfig",
9899
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
100+
w.Header().Add("content-type", "application/json")
99101
fmt.Fprintln(w, strings.TrimSpace(malformedCanaryConfigListJson))
100102
}))
101103
return httptest.NewServer(mux)
@@ -105,6 +107,7 @@ func testGateCanaryConfigListMalformed() *httptest.Server {
105107
// to direct requests to. Responds with a 500 InternalServerError.
106108
func testGateFail() *httptest.Server {
107109
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
110+
w.Header().Add("content-type", "application/json")
108111
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
109112
}))
110113
}

cmd/canary/canary-config/retro_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ func TestCanaryConfigRetro_timeout(t *testing.T) {
169169
func gateServerRetroPass() *httptest.Server {
170170
mux := util.TestGateMuxWithVersionHandler()
171171
mux.Handle("/v2/canaries/canary", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
172+
w.Header().Add("content-type", "application/json")
172173
w.Write([]byte(canaryExecRespJson))
173174
}))
174175

175176
mux.Handle("/v2/canaries/canary/executionId", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
177+
w.Header().Add("content-type", "application/json")
176178
w.Write([]byte(canaryFinishedPassJson))
177179
}))
178180
return httptest.NewServer(mux)
@@ -181,10 +183,12 @@ func gateServerRetroPass() *httptest.Server {
181183
func gateServerExecHang() *httptest.Server {
182184
mux := util.TestGateMuxWithVersionHandler()
183185
mux.Handle("/v2/canaries/canary", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
186+
w.Header().Add("content-type", "application/json")
184187
w.Write([]byte(canaryExecRespJson))
185188
}))
186189

187190
mux.Handle("/v2/canaries/canary/executionId", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
191+
w.Header().Add("content-type", "application/json")
188192
w.Write([]byte(canaryUnfinishedJson))
189193
}))
190194
return httptest.NewServer(mux)

cmd/pipeline/get_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func TestPipelineGet_notfound(t *testing.T) {
144144
func testGatePipelineGetSuccess() *httptest.Server {
145145
mux := util.TestGateMuxWithVersionHandler()
146146
mux.Handle("/applications/app/pipelineConfigs/one", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
147+
w.Header().Add("content-type", "application/json")
147148
fmt.Fprintln(w, strings.TrimSpace(pipelineGetJson))
148149
}))
149150
return httptest.NewServer(mux)

cmd/project/save_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func testGateProjectSaveSuccess(buffer io.Writer) *httptest.Server {
198198
util.NewTestBufferHandlerFunc(http.MethodPost, buffer, http.StatusOK, strings.TrimSpace(testAppTaskRefJsonStr)),
199199
)
200200
mux.Handle("/tasks/id", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
201+
w.Header().Add("content-type", "application/json")
201202
fmt.Fprintln(w, strings.TrimSpace(testProjectTaskStatusJsonStr))
202203
}))
203204
return httptest.NewServer(mux)

util/test_helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestGateMuxWithVersionHandler() *http.ServeMux {
1919
"version": "Unknown",
2020
}
2121
b, _ := json.Marshal(&payload)
22+
w.Header().Add("content-type", "application/json")
2223
fmt.Fprintln(w, string(b))
2324
}))
2425

@@ -58,6 +59,7 @@ func NewTestBufferHandlerFunc(method string, requestBuffer io.Writer, responseHe
5859
}
5960

6061
// Empty response body. Status: 200 Success
62+
w.Header().Add("content-type", "application/json")
6163
w.WriteHeader(responseHeader)
6264
fmt.Fprintln(w, responseBody)
6365
})

0 commit comments

Comments
 (0)