@@ -17,12 +17,21 @@ func routingBTestServer(env Env) (Status, Headers, Body) {
17
17
return 200 , Headers {}, Body ("Server B" )
18
18
}
19
19
20
+ func routingCTestServer (env Env ) (Status , Headers , Body ) {
21
+ if env ["Routing.matches" ].([]string )[1 ] == "123" {
22
+ return 200 , Headers {}, Body ("Server C" )
23
+ }
24
+
25
+ return 500 , Headers {}, Body ("Test Failed" )
26
+ }
27
+
20
28
func TestRoutingSuccess (t * testing.T ) {
21
29
// Compile the stack
22
30
routingStack := new (Stack )
23
31
routes := make (map [string ]App )
24
32
routes ["/a" ] = routingATestServer
25
33
routes ["/b" ] = routingBTestServer
34
+ routes ["/c/(.*)" ] = routingCTestServer
26
35
routingStack .Middleware (Routing (routes ))
27
36
routingApp := routingStack .Compile (routingTestServer )
28
37
@@ -59,6 +68,23 @@ func TestRoutingSuccess(t *testing.T) {
59
68
if string (body ) != expected {
60
69
t .Error ("Expected body:" , string (body ), "to equal:" , expected )
61
70
}
71
+
72
+ // Request against C
73
+ request , err = http .NewRequest ("GET" , "http://localhost:3000/c/123" , nil )
74
+ status , _ , body = routingApp (Env {"mango.request" : & Request {request }})
75
+
76
+ if err != nil {
77
+ t .Error (err )
78
+ }
79
+
80
+ if status != 200 {
81
+ t .Error ("Expected status to equal 200, got:" , status )
82
+ }
83
+
84
+ expected = "Server C"
85
+ if string (body ) != expected {
86
+ t .Error ("Expected body:" , string (body ), "to equal:" , expected )
87
+ }
62
88
}
63
89
64
90
func TestRoutingFailure (t * testing.T ) {
0 commit comments