-
Notifications
You must be signed in to change notification settings - Fork 1
/
router_test.go
48 lines (39 loc) · 1.51 KB
/
router_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
package main
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"mia_template_service_name_placeholder/config"
"github.com/gofiber/fiber/v2"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
)
func TestSetupRouter(t *testing.T) {
log, _ := test.NewNullLogger()
env := config.EnvironmentVariables{
ServiceVersion: "my-version",
HTTPPort: "3000",
ServicePrefix: "my-prefix",
}
app, err := setupRouter(env, log)
require.NoError(t, err, "unexpected error")
t.Run("API documentation is correctly exposed without prefix - json", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/documentations/json", 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.True(t, string(body) != "", "The response body should not be an empty string")
})
t.Run("API documentation is correctly exposed without prefix - yaml", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/documentations/yaml", 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.True(t, string(body) != "", "The response body should not be an empty string")
})
}