Skip to content

Instantly share code, notes, and snippets.

@krishbhanushali
Created April 16, 2019 23:39
Show Gist options
  • Save krishbhanushali/061bcc665f6829148c214ad82f1cd5d6 to your computer and use it in GitHub Desktop.
Save krishbhanushali/061bcc665f6829148c214ad82f1cd5d6 to your computer and use it in GitHub Desktop.
func TestDeleteEntry(t *testing.T) {
req, err := http.NewRequest("DELETE", "/entry", nil)
if err != nil {
t.Fatal(err)
}
q := req.URL.Query()
q.Add("id", "4")
req.URL.RawQuery = q.Encode()
rr := httptest.NewRecorder()
handler := http.HandlerFunc(DeleteEntry)
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