From 8c7458812dd0fb02937041fc35074beaa8326f90 Mon Sep 17 00:00:00 2001 From: Peltoche Date: Thu, 3 Jan 2019 14:57:20 +0100 Subject: [PATCH] Add a /ping endpoint This endpoint can be used to check the service liveness. It can be used for the kubernetes liveness and readiness probs. --- internal/app/api/api.go | 1 + internal/app/api/api_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 internal/app/api/api_test.go diff --git a/internal/app/api/api.go b/internal/app/api/api.go index 1ddbbcf0..f3f380a1 100644 --- a/internal/app/api/api.go +++ b/internal/app/api/api.go @@ -67,6 +67,7 @@ func setup() *echo.Echo { return nil } }) + e.GET("/ping", func(c echo.Context) error { return nil }) e.POST("/merge", merge) g := e.Group("/convert") g.POST("/html", convertHTML) diff --git a/internal/app/api/api_test.go b/internal/app/api/api_test.go new file mode 100644 index 00000000..56917ec0 --- /dev/null +++ b/internal/app/api/api_test.go @@ -0,0 +1,20 @@ +package api + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/labstack/echo" + "github.com/stretchr/testify/assert" +) + +func TestPing(t *testing.T) { + req := httptest.NewRequest(http.MethodGet, "/ping", nil) + rec := httptest.NewRecorder() + + e := echo.New() + _ = e.NewContext(req, rec) + + assert.Equal(t, http.StatusOK, rec.Code) +}