-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_domain_test.go
50 lines (42 loc) · 1.22 KB
/
router_domain_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
package cotton
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDomainAfterGroup(t *testing.T) {
assert.PanicsWithError(t, "group can not call Domain", func() {
router := NewRouter()
router.Group("/hello", nil).Domain("www", nil)
})
}
func TestDomainAfterDomain(t *testing.T) {
assert.PanicsWithError(t, "Domain can not call Domain", func() {
router := NewRouter()
router.Domain("/hello", nil).Domain("www", nil)
})
}
func TestDomainExists(t *testing.T) {
assert.PanicsWithError(t, "domain [www] is exists", func() {
router := NewRouter()
router.Domain("www", nil)
router.Domain("www", nil)
})
}
func TestDomain(t *testing.T) {
router := NewRouter()
d1 := router.Domain("a.test.com")
d1.Get("/test", func(ctx *Context) {
ctx.String(http.StatusOK, "d1 test")
})
d2 := router.Domain("b.test.com")
d2.Get("/test", func(ctx *Context) {
ctx.String(http.StatusOK, "d2 test")
})
w := doRequest(router, http.MethodGet, "http://a.test.com/test")
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "d1 test", w.Body.String())
w = doRequest(router, http.MethodGet, "http://b.test.com/test")
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "d2 test", w.Body.String())
}