-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_test.go
44 lines (38 loc) · 928 Bytes
/
hello_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
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
func TestHealth(t *testing.T) {
// Setup
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/health", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/health/")
// Assertions
if assert.NoError(t, health(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "{\n \"status\": \"OK\"\n}\n", rec.Body.String())
}
}
func TestHelloWorld(t *testing.T) {
// Setup
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/")
// Assertions
if assert.NoError(t, helloWorld(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(
t,
"{\n \"message\": \"Hello world!\",\n \"region\": \"localhost\"\n}\n",
rec.Body.String(),
)
}
}