-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_test.go
45 lines (37 loc) · 1.14 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
package serverfull
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
)
func TestRouterHasHealthCheck(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
fetcher := NewMockFetcher(ctrl)
conf := &RouterConfig{
Fetcher: fetcher,
}
router := NewRouter(conf)
resp := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, "http://localhost/healthcheck", http.NoBody)
router.ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)
}
func TestRouterHasLambdaInvoke(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
fn := NewMockFunction(ctrl)
fetcher := NewMockFetcher(ctrl)
conf := &RouterConfig{
Fetcher: fetcher,
}
router := NewRouter(conf)
resp := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodPost, "http://localhost/2015-03-31/functions/TESTFUNCTION/invocations", http.NoBody)
fetcher.EXPECT().Fetch(gomock.Any(), "TESTFUNCTION").Return(fn, nil)
fn.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return([]byte{}, nil)
router.ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)
}