From 17020ad1340d677ec23c32848f56dab830200a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Mon, 7 Oct 2019 07:33:35 +0200 Subject: [PATCH] Some tests for Get/Post/Put/Delete utility functions --- internal/http/request_test.go | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/internal/http/request_test.go b/internal/http/request_test.go index 72e87b5..cb5f458 100644 --- a/internal/http/request_test.go +++ b/internal/http/request_test.go @@ -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") + } +}