-
Notifications
You must be signed in to change notification settings - Fork 91
/
route_test.go
52 lines (41 loc) · 1.04 KB
/
route_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 (
"log"
"net/http/httptest"
"testing"
"github.com/gjbae1212/hit-counter/handler"
"github.com/alicebob/miniredis"
echo "github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
func TestAddRoute(t *testing.T) {
assert := assert.New(t)
err := AddRoute(nil, "")
assert.Error(err)
s, err := miniredis.Run()
assert.NoError(err)
defer s.Close()
err = AddRoute(echo.New(), s.Addr())
assert.NoError(err)
}
func TestGroup(t *testing.T) {
assert := assert.New(t)
e := echo.New()
mockHandler := func(c echo.Context) error {
log.Println("call????")
return nil
}
r := httptest.NewRequest("GET", "http://localhost?url=github.com", nil)
r.Header.Set(echo.HeaderXForwardedFor, "127.0.0.1")
w := httptest.NewRecorder()
hctx := &handler.HitCounterContext{Context: e.NewContext(r, w)}
// group api
funcs, err := groupApiCount()
assert.NoError(err)
f := funcs[0]
err = f(mockHandler)(hctx)
assert.NoError(err)
assert.NotNil(hctx.Get("host"))
assert.NotNil(hctx.Get("path"))
assert.NotNil(hctx.Get("title"))
}