From a88766080fc64fd5ede6d3f6833156c82cc4b0b0 Mon Sep 17 00:00:00 2001 From: Fabian Vowie Date: Mon, 27 Dec 2021 00:12:33 +0100 Subject: [PATCH] Add test for index route --- go.mod | 7 +++++++ go.sum | 10 ++++++++++ main_test.go | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 main_test.go diff --git a/go.mod b/go.mod index e8488cb..7829019 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,10 @@ module github.com/geplauder/lithium go 1.17 require github.com/gorilla/mux v1.8.0 + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.7.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/go.sum b/go.sum index 5350288..e2ff782 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,12 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..59a0cc1 --- /dev/null +++ b/main_test.go @@ -0,0 +1,21 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIndexRoute(t *testing.T) { + t.Run("test", func(t *testing.T) { + request := httptest.NewRequest(http.MethodGet, "/", nil) + responseRecorder := httptest.NewRecorder() + + IndexHandler(responseRecorder, request) + + assert.Equal(t, responseRecorder.Code, 200, "Response code should be 200") + assert.NotNil(t, responseRecorder.Body, "Response should contain body") + }) +}