Some tests for Get/Post/Put/Delete utility functions

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-07 07:33:35 +02:00
parent 0b056f6cf0
commit 17020ad134
+68
View File
@@ -133,3 +133,71 @@ func TestSendContentType(t *testing.T) {
t.Error("No expected endpoint called")
}
}
func TestGetRequestsWithMethodGet(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Get("/").
Reply(http.StatusOK)
err := Get("http://localhost/", "", nil, nil)
if err != nil {
t.Errorf("Unexpected error %q", err)
}
if !gock.IsDone() {
t.Error("No expected endpoint called")
}
}
func TestPostRequestsWithMethodPost(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Post("/").
Reply(http.StatusOK)
err := Post("http://localhost/", "", nil, nil)
if err != nil {
t.Errorf("Unexpected error %q", err)
}
if !gock.IsDone() {
t.Error("No expected endpoint called")
}
}
func TestPutRequestsWithMethodPut(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Put("/").
Reply(http.StatusOK)
err := Put("http://localhost/", "", nil, nil)
if err != nil {
t.Errorf("Unexpected error %q", err)
}
if !gock.IsDone() {
t.Error("No expected endpoint called")
}
}
func TestDeleteRequestsWithMethodDelete(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Delete("/").
Reply(http.StatusOK)
err := Delete("http://localhost/", "", nil, nil)
if err != nil {
t.Errorf("Unexpected error %q", err)
}
if !gock.IsDone() {
t.Error("No expected endpoint called")
}
}