Skip to content

Commit

Permalink
fix the response code portion
Browse files Browse the repository at this point in the history
fix the response code portion
  • Loading branch information
notnmeyer committed Oct 20, 2023
1 parent dbaca69 commit 49de1c4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -9,24 +10,24 @@ import (
func TestHandlerValidRequest(t *testing.T) {
expectedContentType := "application/json; charset=utf-8"
expectedResponseBody := `{"foo":"bar"}`
expectedResponseCode := "418" // http.StatusTeapot
expectedResponseCode := http.StatusTeapot

// set up the request
req, err := http.NewRequest("POST", "/test", nil)
if err != nil {
t.Fatal(err)
}
req.Header.Add("X-Response-Json", expectedResponseBody)
req.Header.Add("X-Response-Code", expectedResponseCode)
req.Header.Add("X-Response-Code", fmt.Sprint(expectedResponseCode))

// make the request
rr := httptest.NewRecorder()
h := http.HandlerFunc(handler)
h.ServeHTTP(rr, req)

// status code
if status := rr.Code; status != http.StatusTeapot {
t.Errorf("handler returned wrong status code: got '%d' want '%d'", status, http.StatusOK)
if status := rr.Code; status != expectedResponseCode {
t.Errorf("handler returned wrong status code: got '%d' want '%d'", status, expectedResponseCode)
}

// response body
Expand Down

0 comments on commit 49de1c4

Please sign in to comment.