-
Notifications
You must be signed in to change notification settings - Fork 0
/
blueprint_test.go
41 lines (34 loc) · 984 Bytes
/
blueprint_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
package mockgopher
import (
"testing"
"github.com/gorilla/mux"
)
func TestNewBlueprint(t *testing.T) {
blueprint := NewBlueprint("0.0.0.0", 3000)
if blueprint.Host != "0.0.0.0" {
t.Errorf("Host is not set correctly.")
}
}
func TestRegisterRoutes(t *testing.T) {
blueprint := NewBlueprint("0.0.0.0", 3000)
blueprint.AddRoute("/posts", "GET", "")
if len(blueprint.Routes) != 1 {
t.Errorf("Router should have 1 route, have %v route(s).", len(blueprint.Routes))
}
}
func TestMakeRoutes(t *testing.T) {
blueprint := NewBlueprint("0.0.0.0", 3000)
blueprint.AddRoute("/posts", "GET", "")
router := blueprint.MakeRouter()
postsRouteFound := false
router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
routePathRegexp, _ := route.GetPathRegexp()
if routePathRegexp == "^/posts$" {
postsRouteFound = true
}
return nil
})
if !postsRouteFound {
t.Errorf("Route \"/posts\" not found in *mux.Router from MakeRouter().")
}
}