From 065785fdc409224718fa0dd6b9507e13a9c60532 Mon Sep 17 00:00:00 2001 From: Igor Rzegocki Date: Sun, 3 Oct 2021 19:58:24 +0200 Subject: [PATCH] healthcheck endpoint --- pkg/integrations/healthcheck_test.go | 33 ++++++++++++++++++++++++++++ pkg/routes/healthcheck.go | 28 +++++++++++++++++++++++ pkg/routes/routes.go | 3 +++ 3 files changed, 64 insertions(+) create mode 100644 pkg/integrations/healthcheck_test.go create mode 100644 pkg/routes/healthcheck.go diff --git a/pkg/integrations/healthcheck_test.go b/pkg/integrations/healthcheck_test.go new file mode 100644 index 000000000..7c77f2619 --- /dev/null +++ b/pkg/integrations/healthcheck_test.go @@ -0,0 +1,33 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-2021 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public Licensee as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public Licensee for more details. +// +// You should have received a copy of the GNU Affero General Public Licensee +// along with this program. If not, see . + +package integrations + +import ( + "net/http" + "testing" + + "code.vikunja.io/api/pkg/routes" + "github.com/stretchr/testify/assert" +) + +func TestHealthcheck(t *testing.T) { + t.Run("healthcheck", func(t *testing.T) { + rec, err := newTestRequest(t, http.MethodGet, routes.HealthcheckHandler, ``, nil, nil) + assert.NoError(t, err) + assert.Contains(t, rec.Body.String(), "OK") + }) +} diff --git a/pkg/routes/healthcheck.go b/pkg/routes/healthcheck.go new file mode 100644 index 000000000..8ce2b37fe --- /dev/null +++ b/pkg/routes/healthcheck.go @@ -0,0 +1,28 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-2021 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public Licensee as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public Licensee for more details. +// +// You should have received a copy of the GNU Affero General Public Licensee +// along with this program. If not, see . + +package routes + +import ( + "net/http" + + "github.com/labstack/echo/v4" +) + +// HealthcheckHandler handles healthckeck 'OK' response +func HealthcheckHandler(c echo.Context) error { + return c.String(http.StatusOK, "OK") +} diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index b340aa6da..f0bac0832 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -198,6 +198,9 @@ func RegisterRoutes(e *echo.Echo) { registerCalDavRoutes(c) } + // healthcheck + e.GET("/health", HealthcheckHandler) + // CORS_SHIT if config.CorsEnable.GetBool() { e.Use(middleware.CORSWithConfig(middleware.CORSConfig{