Browse code

integration-cli: fix getTestTokenService not sending header

This utility was setting the content-type header after WriteHeader was
called, and the header was not sent because of that.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/09/27 20:57:48
Showing 1 changed files
... ...
@@ -235,13 +235,13 @@ func getTestTokenService(status int, body string, retries int) *httptest.Server
235 235
 	return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
236 236
 		mu.Lock()
237 237
 		if retries > 0 {
238
-			w.WriteHeader(http.StatusServiceUnavailable)
239 238
 			w.Header().Set("Content-Type", "application/json")
239
+			w.WriteHeader(http.StatusServiceUnavailable)
240 240
 			w.Write([]byte(`{"errors":[{"code":"UNAVAILABLE","message":"cannot create token at this time"}]}`))
241 241
 			retries--
242 242
 		} else {
243
-			w.WriteHeader(status)
244 243
 			w.Header().Set("Content-Type", "application/json")
244
+			w.WriteHeader(status)
245 245
 			w.Write([]byte(body))
246 246
 		}
247 247
 		mu.Unlock()