-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_test.go
60 lines (46 loc) · 1.28 KB
/
controller_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
53
54
55
56
57
58
59
60
package grok_test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/recoli-tech/grok"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type APIControllerTestSuite struct {
suite.Suite
assert *assert.Assertions
settings *grok.Settings
server *grok.API
}
type testContainer struct{}
func (c *testContainer) Controllers() []grok.APIController {
return nil
}
func (c *testContainer) Close() error {
return nil
}
func TestAPIControllerTestSuite(t *testing.T) {
suite.Run(t, new(APIControllerTestSuite))
}
func (s *APIControllerTestSuite) SetupTest() {
container := &testContainer{}
s.assert = assert.New(s.T())
s.settings = &grok.Settings{}
grok.FromYAML("tests/config.yaml", s.settings)
s.server = grok.New(
grok.WithSettings(s.settings),
grok.WithContainer(container))
}
func (s *APIControllerTestSuite) TestNotFound() {
req := httptest.NewRequest("GET", "/notfound", nil)
response := httptest.NewRecorder()
s.server.Engine.ServeHTTP(response, req)
s.assert.Equal(http.StatusNotFound, response.Code)
}
func (s *APIControllerTestSuite) TestSwagger() {
req := httptest.NewRequest("GET", "/swagger", nil)
response := httptest.NewRecorder()
s.server.Engine.ServeHTTP(response, req)
s.assert.Equal(http.StatusOK, response.Code)
}