// Homework 45, problem 3: Test a counter API. // // Write the three tests below. Each one starts with a fresh counter. package main import ( "net/http/httptest" "strings" "testing" ) // send runs one request through the routes and returns what was written. func send(method string, target string, body string) *httptest.ResponseRecorder { request := httptest.NewRequest(method, target, strings.NewReader(body)) recorder := httptest.NewRecorder() routes().ServeHTTP(recorder, request) return recorder } // TestGetStartsAtZero checks that GET /api/counter gives status 200, the // Content-Type application/json, and a value of 0. func TestGetStartsAtZero(t *testing.T) { count = &counter{} t.Skip("TODO: write this test") } // TestAddThenGet adds 5 and then 3, and checks that GET gives 8. func TestAddThenGet(t *testing.T) { count = &counter{} t.Skip("TODO: write this test") } // TestAddRejectsBadInput is table-driven. Each bad body must give status 400 // and leave the counter at 0. Try: not JSON, an unknown field, by 0, by 101, // and by as text. func TestAddRejectsBadInput(t *testing.T) { t.Skip("TODO: write this test") }