forked from FunOrgByNaga/go_echo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
44 lines (36 loc) · 939 Bytes
/
main_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 TestGetGhost(t *testing.T) {
// Setup
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/echo/statement")
// Assertions
if assert.NoError(t, getGhost(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "oooOOOoooOOOooo\n", rec.Body.String())
}
}
func TestGetEcho(t *testing.T) {
// Setup
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/echo/statement", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/echo/")
c.SetParamNames("statement")
c.SetParamValues("statement")
// Assertions
if assert.NoError(t, getEcho(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "statement statement\n", rec.Body.String())
}
}