Created
April 11, 2019 04:58
-
-
Save krishbhanushali/fe667c86e79a478eea7a7dc5ed3782d0 to your computer and use it in GitHub Desktop.
This Gist gives you the rough idea about how to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestGetEntries(t *testing.T) { | |
req, err := http.NewRequest("GET", "/entries", nil) | |
if err != nil { | |
t.Fatal(err) | |
} | |
rr := httptest.NewRecorder() | |
handler := http.HandlerFunc(GetEntries) | |
handler.ServeHTTP(rr, req) | |
if status := rr.Code; status != http.StatusOK { | |
t.Errorf("handler returned wrong status code: got %v want %v", | |
status, http.StatusOK) | |
} | |
// Check the response body is what we expect. | |
expected := `[{"id":1,"first_name":"Krish","last_name":"Bhanushali","email_address":"[email protected]","phone_number":"0987654321"},{"id":2,"first_name":"xyz","last_name":"pqr","email_address":"[email protected]","phone_number":"1234567890"},{"id":6,"first_name":"FirstNameSample","last_name":"LastNameSample","email_address":"[email protected]","phone_number":"1111111111"}]` | |
if rr.Body.String() != expected { | |
t.Errorf("handler returned unexpected body: got %v want %v", | |
rr.Body.String(), expected) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment