package bugbox import ( "fmt" "net/http" "net/http/httptest" "testing" ) func newGETEnclosureRequest(name string) *http.Request { request, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/enclosure/%s", name), nil) return request } func assertResponseBody(t testing.TB, got, want string) { t.Helper() if got != want { // a %q is a double quoted string t.Errorf("got %q, want %q", got, want) } } func TestGETEnclosures(t *testing.T) { t.Run("returns enclosure 1337", func(t *testing.T) { // nil is used since we are not providing a request body request := newGETEnclosureRequest("1337") // response is a ResponseRecorder used for spying on response response := httptest.NewRecorder() BugBoxServer(response, request) assertResponseBody(t, response.Body.String(), "1337") }) t.Run("returns enclosure 7331", func(t *testing.T) { // nil is used since we are not providing a request body request := newGETEnclosureRequest("7331") // response is a ResponseRecorder used for spying on response response := httptest.NewRecorder() BugBoxServer(response, request) assertResponseBody(t, response.Body.String(), "7331") }) }