-
Notifications
You must be signed in to change notification settings - Fork 0
/
swagger_test.go
44 lines (39 loc) · 1.04 KB
/
swagger_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 biu_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tuotoo/biu"
"github.com/tuotoo/biu/opt"
)
type SwaggerTest struct{}
func (ctl SwaggerTest) WebService(ws biu.WS) {
authOpt := opt.EnableAuth()
ws.Route(ws.GET("/"), authOpt)
ws.Route(ws.GET("/no/auth"))
ws.Route(ws.POST("/"), authOpt)
ws.Route(ws.PATCH("/"), authOpt)
ws.Route(ws.DELETE("/"), authOpt)
ws.Route(ws.HEAD("/"), authOpt)
ws.Route(ws.PUT("/"), authOpt)
}
func TestNewSwaggerService(t *testing.T) {
biu.AddServices("/v1", nil, biu.NS{
NameSpace: "test",
Controller: SwaggerTest{},
})
routes := biu.NewSwaggerService(biu.SwaggerInfo{
Title: "title",
Description: "desc",
TermsOfService: "tos",
ContactName: "contactName",
ContactEmail: "contactEmail",
ContactURL: "contactURL",
LicenseName: "licenseName",
LicenseURL: "licenseURL",
Version: "1.0",
RoutePrefix: "/v1",
}).Routes()
assert.Len(t, routes, 1)
route := routes[0]
assert.Equal(t, "GET /v1/swagger.json", route.String())
}