-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrouter_test.go
53 lines (41 loc) · 1.04 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
46
47
48
49
50
51
52
53
package falcore
import (
"net/http"
"regexp"
"testing"
)
type SimpleFilter int
func (sf SimpleFilter) FilterRequest(req *Request) *http.Response {
sf = -sf
return nil
}
func TestRegexpRoute(t *testing.T) {
r := new(RegexpRoute)
var sf1 SimpleFilter = 1
r.Filter = sf1
r.Match = regexp.MustCompile(`one`)
if r.MatchString("http://tester.com/one") != sf1 {
t.Errorf("Failed to match regexp")
}
if r.MatchString("http://tester.com/two") != nil {
t.Errorf("False regexp match")
}
}
func TestHostRouter(t *testing.T) {
hr := NewHostRouter()
var sf1 SimpleFilter = 1
var sf2 SimpleFilter = 2
hr.AddMatch("www.ngmoco.com", sf1)
hr.AddMatch("developer.ngmoco.com", sf2)
req := validGetRequest()
req.HttpRequest.Host = "developer.ngmoco.com"
filt := hr.SelectPipeline(req)
if filt != sf2 {
t.Errorf("Host router didn't get the right pipeline")
}
req.HttpRequest.Host = "ngmoco.com"
filt = hr.SelectPipeline(req)
if filt != nil {
t.Errorf("Host router got currently unsupported fuzzy match so you should update this test")
}
}