Created
April 16, 2019 23:37
-
-
Save krishbhanushali/8d7c4fef2a56bbfa8861a769def8e0f7 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 TestEditEntry(t *testing.T) { | |
var jsonStr = []byte(`{"id":4,"first_name":"xyz change","last_name":"pqr","email_address":"xyz@pqr.com","phone_number":"1234567890"}`) | |
req, err := http.NewRequest("PUT", "/entry", bytes.NewBuffer(jsonStr)) | |
if err != nil { | |
t.Fatal(err) | |
} | |
req.Header.Set("Content-Type", "application/json") | |
rr := httptest.NewRecorder() | |
handler := http.HandlerFunc(UpdateEntry) | |
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 change","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