From 38434cef27a6b95fd5d680fd7d3c7385a01ddfeb Mon Sep 17 00:00:00 2001 From: Felix Auringer <48409110+felixauringer@users.noreply.github.com> Date: Mon, 26 Apr 2021 12:30:26 +0200 Subject: [PATCH] Add tests for health route --- .gitlab-ci.yml | 2 +- api/health_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 api/health_test.go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 262726f..0027949 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,4 +23,4 @@ test: stage: test needs: [] script: - - go test -v + - go test ./... -v diff --git a/api/health_test.go b/api/health_test.go new file mode 100644 index 0000000..f378ce8 --- /dev/null +++ b/api/health_test.go @@ -0,0 +1,23 @@ +package api + +import ( + "encoding/json" + "github.com/stretchr/testify/assert" + "net/http" + "net/http/httptest" + "testing" +) + +func TestHealthRoute(t *testing.T) { + req, err := http.NewRequest("GET", "/health", nil) + if err != nil { + t.Fatal(err) + } + rec := httptest.NewRecorder() + http.HandlerFunc(Health).ServeHTTP(rec, req) + res := &Message{} + _ = json.NewDecoder(rec.Body).Decode(res) + + assert.Equal(t, http.StatusOK, rec.Code) + assert.Equal(t, "I'm alive!", res.Msg) +}