-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusroutes_test.go
52 lines (46 loc) · 2.03 KB
/
statusroutes_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/require"
)
func TestStatusRoutes(t *testing.T) {
app := fiber.New()
serviceName := "my-service-name"
serviceVersion := "0.0.0"
StatusRoutes(app, serviceName, serviceVersion)
t.Run("/-/healthz - ok", func(t *testing.T) {
expectedResponse := fmt.Sprintf("{\"status\":\"OK\",\"name\":\"%s\",\"version\":\"%s\"}", serviceName, serviceVersion)
request := httptest.NewRequest(http.MethodGet, "/-/healthz", nil)
response, err := app.Test(request)
require.NoError(t, err)
require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200")
body, readBodyError := io.ReadAll(response.Body)
require.NoError(t, readBodyError)
require.Equal(t, expectedResponse, string(body), "The response body should be the expected one")
})
t.Run("/-/ready - ok", func(t *testing.T) {
expectedResponse := fmt.Sprintf("{\"status\":\"OK\",\"name\":\"%s\",\"version\":\"%s\"}", serviceName, serviceVersion)
request := httptest.NewRequest(http.MethodGet, "/-/ready", nil)
response, err := app.Test(request)
require.NoError(t, err)
require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200")
body, readBodyError := io.ReadAll(response.Body)
require.NoError(t, readBodyError)
require.Equal(t, expectedResponse, string(body), "The response body should be the expected one")
})
t.Run("/-/check-up - ok", func(t *testing.T) {
expectedResponse := fmt.Sprintf("{\"status\":\"OK\",\"name\":\"%s\",\"version\":\"%s\"}", serviceName, serviceVersion)
request := httptest.NewRequest(http.MethodGet, "/-/check-up", nil)
response, err := app.Test(request)
require.NoError(t, err)
require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200")
body, readBodyError := io.ReadAll(response.Body)
require.NoError(t, readBodyError)
require.Equal(t, expectedResponse, string(body), "The response body should be the expected one")
})
}