Browse Source

Clean up some naming in mux_test.go

pull/179/head
Kamil Kisiel 10 years ago
parent
commit
327d4b684c
  1. 130
      mux_test.go

130
mux_test.go

@ -31,8 +31,8 @@ type routeTest struct {
vars map[string]string // the expected vars of the match vars map[string]string // the expected vars of the match
host string // the expected host of the match host string // the expected host of the match
path string // the expected path of the match path string // the expected path of the match
path_template string // the expected path template to match pathTemplate string // the expected path template to match
host_template string // the expected host template to match hostTemplate string // the expected host template to match
shouldMatch bool // whether the request is expected to match the route at all shouldMatch bool // whether the request is expected to match the route at all
shouldRedirect bool // whether the request should result in a redirect shouldRedirect bool // whether the request should result in a redirect
} }
@ -120,7 +120,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v1": "bbb"}, vars: map[string]string{"v1": "bbb"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `aaa.{v1:[a-z]{3}}.ccc`, hostTemplate: `aaa.{v1:[a-z]{3}}.ccc`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -130,7 +130,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v1": "bbb"}, vars: map[string]string{"v1": "bbb"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `aaa.{v1:[a-z]{2}(b|c)}.ccc`, hostTemplate: `aaa.{v1:[a-z]{2}(b|c)}.ccc`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -140,7 +140,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v1": "bbb"}, vars: map[string]string{"v1": "bbb"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `aaa.{v1:[a-z]{3}}.ccc`, hostTemplate: `aaa.{v1:[a-z]{3}}.ccc`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -150,7 +150,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc"}, vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`, hostTemplate: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -160,7 +160,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc"}, vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`, hostTemplate: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -170,7 +170,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v-1": "bbb"}, vars: map[string]string{"v-1": "bbb"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `aaa.{v-1:[a-z]{3}}.ccc`, hostTemplate: `aaa.{v-1:[a-z]{3}}.ccc`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -180,7 +180,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v-1": "bbb"}, vars: map[string]string{"v-1": "bbb"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `aaa.{v-1:[a-z]{2}(b|c)}.ccc`, hostTemplate: `aaa.{v-1:[a-z]{2}(b|c)}.ccc`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -190,7 +190,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"v-1": "aaa", "v-2": "bbb", "v-3": "ccc"}, vars: map[string]string{"v-1": "aaa", "v-2": "bbb", "v-3": "ccc"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "", path: "",
host_template: `{v-1:[a-z]{3}}.{v-2:[a-z]{3}}.{v-3:[a-z]{3}}`, hostTemplate: `{v-1:[a-z]{3}}.{v-2:[a-z]{3}}.{v-3:[a-z]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -200,7 +200,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"category": "a"}, vars: map[string]string{"category": "a"},
host: "", host: "",
path: "/a", path: "/a",
path_template: `/{category:a|b/c}`, pathTemplate: `/{category:a|b/c}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -210,7 +210,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"category": "b/c"}, vars: map[string]string{"category": "b/c"},
host: "", host: "",
path: "/b/c", path: "/b/c",
path_template: `/{category:a|b/c}`, pathTemplate: `/{category:a|b/c}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -220,7 +220,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"category": "a", "product": "product_name", "id": "1"}, vars: map[string]string{"category": "a", "product": "product_name", "id": "1"},
host: "", host: "",
path: "/a/product_name/1", path: "/a/product_name/1",
path_template: `/{category:a|b/c}/{product}/{id:[0-9]+}`, pathTemplate: `/{category:a|b/c}/{product}/{id:[0-9]+}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -230,7 +230,7 @@ func TestHost(t *testing.T) {
vars: map[string]string{"category": "b/c", "product": "product_name", "id": "1"}, vars: map[string]string{"category": "b/c", "product": "product_name", "id": "1"},
host: "", host: "",
path: "/b/c/product_name/1", path: "/b/c/product_name/1",
path_template: `/{category:a|b/c}/{product}/{id:[0-9]+}`, pathTemplate: `/{category:a|b/c}/{product}/{id:[0-9]+}`,
shouldMatch: true, shouldMatch: true,
}, },
} }
@ -267,7 +267,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{}, vars: map[string]string{},
host: "", host: "",
path: "/111", path: "/111",
path_template: `/111/`, pathTemplate: `/111/`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -277,7 +277,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{}, vars: map[string]string{},
host: "", host: "",
path: "/111/", path: "/111/",
path_template: `/111`, pathTemplate: `/111`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -296,7 +296,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"v1": "222"}, vars: map[string]string{"v1": "222"},
host: "", host: "",
path: "/111/222/333", path: "/111/222/333",
path_template: `/111/{v1:[0-9]{3}}/333`, pathTemplate: `/111/{v1:[0-9]{3}}/333`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -306,7 +306,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"v1": "222"}, vars: map[string]string{"v1": "222"},
host: "", host: "",
path: "/111/222/333", path: "/111/222/333",
path_template: `/111/{v1:[0-9]{3}}/333`, pathTemplate: `/111/{v1:[0-9]{3}}/333`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -316,7 +316,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"v1": "111", "v2": "222", "v3": "333"}, vars: map[string]string{"v1": "111", "v2": "222", "v3": "333"},
host: "", host: "",
path: "/111/222/333", path: "/111/222/333",
path_template: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}`, pathTemplate: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -326,7 +326,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"v1": "111", "v2": "222", "v3": "333"}, vars: map[string]string{"v1": "111", "v2": "222", "v3": "333"},
host: "", host: "",
path: "/111/222/333", path: "/111/222/333",
path_template: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}`, pathTemplate: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -336,7 +336,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"category": "a", "product": "product_name", "id": "1"}, vars: map[string]string{"category": "a", "product": "product_name", "id": "1"},
host: "", host: "",
path: "/a/product_name/1", path: "/a/product_name/1",
path_template: `/{category:a|(b/c)}/{product}/{id:[0-9]+}`, pathTemplate: `/{category:a|(b/c)}/{product}/{id:[0-9]+}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -346,7 +346,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"v-1": "222"}, vars: map[string]string{"v-1": "222"},
host: "", host: "",
path: "/111/222/333", path: "/111/222/333",
path_template: `/111/{v-1:[0-9]{3}}/333`, pathTemplate: `/111/{v-1:[0-9]{3}}/333`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -356,7 +356,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"v-1": "111", "v-2": "222", "v-3": "333"}, vars: map[string]string{"v-1": "111", "v-2": "222", "v-3": "333"},
host: "", host: "",
path: "/111/222/333", path: "/111/222/333",
path_template: `/{v-1:[0-9]{3}}/{v-2:[0-9]{3}}/{v-3:[0-9]{3}}`, pathTemplate: `/{v-1:[0-9]{3}}/{v-2:[0-9]{3}}/{v-3:[0-9]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -366,7 +366,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"product-category": "a", "product-name": "product_name", "product-id": "1"}, vars: map[string]string{"product-category": "a", "product-name": "product_name", "product-id": "1"},
host: "", host: "",
path: "/a/product_name/1", path: "/a/product_name/1",
path_template: `/{product-category:a|(b/c)}/{product-name}/{product-id:[0-9]+}`, pathTemplate: `/{product-category:a|(b/c)}/{product-name}/{product-id:[0-9]+}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -376,7 +376,7 @@ func TestPath(t *testing.T) {
vars: map[string]string{"type": "daily", "date": "2016-01-01"}, vars: map[string]string{"type": "daily", "date": "2016-01-01"},
host: "", host: "",
path: "/daily-2016-01-01", path: "/daily-2016-01-01",
path_template: `/{type:(?i:daily|mini|variety)}-{date:\d{4,4}-\d{2,2}-\d{2,2}}`, pathTemplate: `/{type:(?i:daily|mini|variety)}-{date:\d{4,4}-\d{2,2}-\d{2,2}}`,
shouldMatch: true, shouldMatch: true,
}, },
} }
@ -423,7 +423,7 @@ func TestPathPrefix(t *testing.T) {
vars: map[string]string{"v1": "222"}, vars: map[string]string{"v1": "222"},
host: "", host: "",
path: "/111/222", path: "/111/222",
path_template: `/111/{v1:[0-9]{3}}`, pathTemplate: `/111/{v1:[0-9]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -433,7 +433,7 @@ func TestPathPrefix(t *testing.T) {
vars: map[string]string{"v1": "222"}, vars: map[string]string{"v1": "222"},
host: "", host: "",
path: "/111/222", path: "/111/222",
path_template: `/111/{v1:[0-9]{3}}`, pathTemplate: `/111/{v1:[0-9]{3}}`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -443,7 +443,7 @@ func TestPathPrefix(t *testing.T) {
vars: map[string]string{"v1": "111", "v2": "222"}, vars: map[string]string{"v1": "111", "v2": "222"},
host: "", host: "",
path: "/111/222", path: "/111/222",
path_template: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}`, pathTemplate: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -453,7 +453,7 @@ func TestPathPrefix(t *testing.T) {
vars: map[string]string{"v1": "111", "v2": "222"}, vars: map[string]string{"v1": "111", "v2": "222"},
host: "", host: "",
path: "/111/222", path: "/111/222",
path_template: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}`, pathTemplate: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}`,
shouldMatch: false, shouldMatch: false,
}, },
} }
@ -473,8 +473,8 @@ func TestHostPath(t *testing.T) {
vars: map[string]string{}, vars: map[string]string{},
host: "", host: "",
path: "", path: "",
path_template: `/111/222/333`, pathTemplate: `/111/222/333`,
host_template: `aaa.bbb.ccc`, hostTemplate: `aaa.bbb.ccc`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -484,8 +484,8 @@ func TestHostPath(t *testing.T) {
vars: map[string]string{}, vars: map[string]string{},
host: "", host: "",
path: "", path: "",
path_template: `/111/222/333`, pathTemplate: `/111/222/333`,
host_template: `aaa.bbb.ccc`, hostTemplate: `aaa.bbb.ccc`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -495,8 +495,8 @@ func TestHostPath(t *testing.T) {
vars: map[string]string{"v1": "bbb", "v2": "222"}, vars: map[string]string{"v1": "bbb", "v2": "222"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "/111/222/333", path: "/111/222/333",
path_template: `/111/{v2:[0-9]{3}}/333`, pathTemplate: `/111/{v2:[0-9]{3}}/333`,
host_template: `aaa.{v1:[a-z]{3}}.ccc`, hostTemplate: `aaa.{v1:[a-z]{3}}.ccc`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -506,8 +506,8 @@ func TestHostPath(t *testing.T) {
vars: map[string]string{"v1": "bbb", "v2": "222"}, vars: map[string]string{"v1": "bbb", "v2": "222"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "/111/222/333", path: "/111/222/333",
path_template: `/111/{v2:[0-9]{3}}/333`, pathTemplate: `/111/{v2:[0-9]{3}}/333`,
host_template: `aaa.{v1:[a-z]{3}}.ccc`, hostTemplate: `aaa.{v1:[a-z]{3}}.ccc`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -517,8 +517,8 @@ func TestHostPath(t *testing.T) {
vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc", "v4": "111", "v5": "222", "v6": "333"}, vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc", "v4": "111", "v5": "222", "v6": "333"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "/111/222/333", path: "/111/222/333",
path_template: `/{v4:[0-9]{3}}/{v5:[0-9]{3}}/{v6:[0-9]{3}}`, pathTemplate: `/{v4:[0-9]{3}}/{v5:[0-9]{3}}/{v6:[0-9]{3}}`,
host_template: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`, hostTemplate: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -528,8 +528,8 @@ func TestHostPath(t *testing.T) {
vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc", "v4": "111", "v5": "222", "v6": "333"}, vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc", "v4": "111", "v5": "222", "v6": "333"},
host: "aaa.bbb.ccc", host: "aaa.bbb.ccc",
path: "/111/222/333", path: "/111/222/333",
path_template: `/{v4:[0-9]{3}}/{v5:[0-9]{3}}/{v6:[0-9]{3}}`, pathTemplate: `/{v4:[0-9]{3}}/{v5:[0-9]{3}}/{v6:[0-9]{3}}`,
host_template: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`, hostTemplate: `{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}`,
shouldMatch: false, shouldMatch: false,
}, },
} }
@ -654,8 +654,8 @@ func TestQueries(t *testing.T) {
vars: map[string]string{}, vars: map[string]string{},
host: "", host: "",
path: "", path: "",
path_template: `/api`, pathTemplate: `/api`,
host_template: `www.example.com`, hostTemplate: `www.example.com`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -665,8 +665,8 @@ func TestQueries(t *testing.T) {
vars: map[string]string{}, vars: map[string]string{},
host: "", host: "",
path: "", path: "",
path_template: `/api`, pathTemplate: `/api`,
host_template: `www.example.com`, hostTemplate: `www.example.com`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -949,7 +949,7 @@ func TestBuildVarsFunc(t *testing.T) {
}), }),
request: newRequest("GET", "http://localhost/111/2"), request: newRequest("GET", "http://localhost/111/2"),
path: "/111/3a", path: "/111/3a",
path_template: `/111/{v1:\d}{v2:.*}`, pathTemplate: `/111/{v1:\d}{v2:.*}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -963,7 +963,7 @@ func TestBuildVarsFunc(t *testing.T) {
}), }),
request: newRequest("GET", "http://localhost/1/a"), request: newRequest("GET", "http://localhost/1/a"),
path: "/2/b", path: "/2/b",
path_template: `/{v1:\d}/{v2:\w}`, pathTemplate: `/{v1:\d}/{v2:\w}`,
shouldMatch: true, shouldMatch: true,
}, },
} }
@ -985,8 +985,8 @@ func TestSubRouter(t *testing.T) {
vars: map[string]string{"v1": "aaa", "v2": "bbb"}, vars: map[string]string{"v1": "aaa", "v2": "bbb"},
host: "aaa.google.com", host: "aaa.google.com",
path: "/bbb", path: "/bbb",
path_template: `/{v2:[a-z]+}`, pathTemplate: `/{v2:[a-z]+}`,
host_template: `{v1:[a-z]+}.google.com`, hostTemplate: `{v1:[a-z]+}.google.com`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -995,8 +995,8 @@ func TestSubRouter(t *testing.T) {
vars: map[string]string{"v1": "aaa", "v2": "bbb"}, vars: map[string]string{"v1": "aaa", "v2": "bbb"},
host: "aaa.google.com", host: "aaa.google.com",
path: "/bbb", path: "/bbb",
path_template: `/{v2:[a-z]+}`, pathTemplate: `/{v2:[a-z]+}`,
host_template: `{v1:[a-z]+}.google.com`, hostTemplate: `{v1:[a-z]+}.google.com`,
shouldMatch: false, shouldMatch: false,
}, },
{ {
@ -1005,7 +1005,7 @@ func TestSubRouter(t *testing.T) {
vars: map[string]string{"v1": "bar", "v2": "ding"}, vars: map[string]string{"v1": "bar", "v2": "ding"},
host: "", host: "",
path: "/foo/bar/baz/ding", path: "/foo/bar/baz/ding",
path_template: `/foo/{v1}/baz/{v2}`, pathTemplate: `/foo/{v1}/baz/{v2}`,
shouldMatch: true, shouldMatch: true,
}, },
{ {
@ -1014,7 +1014,7 @@ func TestSubRouter(t *testing.T) {
vars: map[string]string{"v1": "bar", "v2": "ding"}, vars: map[string]string{"v1": "bar", "v2": "ding"},
host: "", host: "",
path: "/foo/bar/baz/ding", path: "/foo/bar/baz/ding",
path_template: `/foo/{v1}/baz/{v2}`, pathTemplate: `/foo/{v1}/baz/{v2}`,
shouldMatch: false, shouldMatch: false,
}, },
} }
@ -1331,23 +1331,23 @@ func testRoute(t *testing.T, test routeTest) {
func testTemplate(t *testing.T, test routeTest) { func testTemplate(t *testing.T, test routeTest) {
route := test.route route := test.route
path_template := test.path_template pathTemplate := test.pathTemplate
if len(path_template) == 0 { if len(pathTemplate) == 0 {
path_template = test.path pathTemplate = test.path
} }
host_template := test.host_template hostTemplate := test.hostTemplate
if len(host_template) == 0 { if len(hostTemplate) == 0 {
host_template = test.host hostTemplate = test.host
} }
path_tmpl, path_err := route.GetPathTemplate() routePathTemplate, pathErr := route.GetPathTemplate()
if path_err == nil && path_tmpl != path_template { if pathErr == nil && routePathTemplate != pathTemplate {
t.Errorf("(%v) GetPathTemplate not equal: expected %v, got %v", test.title, path_template, path_tmpl) t.Errorf("(%v) GetPathTemplate not equal: expected %v, got %v", test.title, pathTemplate, routePathTemplate)
} }
host_tmpl, host_err := route.GetHostTemplate() routeHostTemplate, hostErr := route.GetHostTemplate()
if host_err == nil && host_tmpl != host_template { if hostErr == nil && routeHostTemplate != hostTemplate {
t.Errorf("(%v) GetHostTemplate not equal: expected %v, got %v", test.title, host_template, host_tmpl) t.Errorf("(%v) GetHostTemplate not equal: expected %v, got %v", test.title, hostTemplate, routeHostTemplate)
} }
} }

Loading…
Cancel
Save