Created
April 16, 2019 21:10
-
-
Save krishbhanushali/bc02991b118a91ca11e838fb63542009 to your computer and use it in GitHub Desktop.
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 TestCreateEntry(t *testing.T) { | |
var jsonStr = []byte(`{"id":4,"first_name":"xyz","last_name":"pqr","email_address":"xyz@pqr.com","phone_number":"1234567890"}`) | |
req, err := http.NewRequest("POST", "/entry", bytes.NewBuffer(jsonStr)) | |
if err != nil { | |
t.Fatal(err) | |
} | |
req.Header.Set("Content-Type", "application/json") | |
rr := httptest.NewRecorder() | |
handler := http.HandlerFunc(CreateEntry) | |
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) | |
} | |
expected := `{"id":4,"first_name":"xyz","last_name":"pqr","email_address":"xyz@pqr.com","phone_number":"1234567890"}` | |
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