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

Loading…
Cancel
Save