1
0
mirror of https://github.com/rancher/os.git synced 2025-09-04 16:21:07 +00:00

migrate to upstream libcompose in one and a half go

This commit is contained in:
Ivan Mikushin
2015-11-26 17:41:42 +05:00
parent 1d691cd8d6
commit 5a363ab97d
1291 changed files with 40107 additions and 123532 deletions

View File

@@ -135,42 +135,6 @@ func TestHost(t *testing.T) {
path: "",
shouldMatch: false,
},
{
title: "Path route with single pattern with pipe, match",
route: new(Route).Path("/{category:a|b/c}"),
request: newRequest("GET", "http://localhost/a"),
vars: map[string]string{"category": "a"},
host: "",
path: "/a",
shouldMatch: true,
},
{
title: "Path route with single pattern with pipe, match",
route: new(Route).Path("/{category:a|b/c}"),
request: newRequest("GET", "http://localhost/b/c"),
vars: map[string]string{"category": "b/c"},
host: "",
path: "/b/c",
shouldMatch: true,
},
{
title: "Path route with multiple patterns with pipe, match",
route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"),
request: newRequest("GET", "http://localhost/a/product_name/1"),
vars: map[string]string{"category": "a", "product": "product_name", "id": "1"},
host: "",
path: "/a/product_name/1",
shouldMatch: true,
},
{
title: "Path route with multiple patterns with pipe, match",
route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"),
request: newRequest("GET", "http://localhost/b/c/product_name/1"),
vars: map[string]string{"category": "b/c", "product": "product_name", "id": "1"},
host: "",
path: "/b/c/product_name/1",
shouldMatch: true,
},
}
for _, test := range tests {
testRoute(t, test)
@@ -434,24 +398,6 @@ func TestHeaders(t *testing.T) {
path: "",
shouldMatch: false,
},
{
title: "Headers route, regex header values to match",
route: new(Route).Headers("foo", "ba[zr]"),
request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "bar"}),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Headers route, regex header values to match",
route: new(Route).HeadersRegexp("foo", "ba[zr]"),
request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "baz"}),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: true,
},
}
for _, test := range tests {
@@ -570,96 +516,6 @@ func TestQueries(t *testing.T) {
path: "",
shouldMatch: false,
},
{
title: "Queries route with regexp pattern with quantifier, match",
route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
request: newRequest("GET", "http://localhost?foo=1"),
vars: map[string]string{"v1": "1"},
host: "",
path: "",
shouldMatch: true,
},
{
title: "Queries route with regexp pattern with quantifier, additional variable in query string, match",
route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
request: newRequest("GET", "http://localhost?bar=2&foo=1"),
vars: map[string]string{"v1": "1"},
host: "",
path: "",
shouldMatch: true,
},
{
title: "Queries route with regexp pattern with quantifier, regexp does not match",
route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
request: newRequest("GET", "http://localhost?foo=12"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with regexp pattern with quantifier, additional variable in query string, regexp does not match",
route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
request: newRequest("GET", "http://localhost?foo=12"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with empty value, should match",
route: new(Route).Queries("foo", ""),
request: newRequest("GET", "http://localhost?foo=bar"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: true,
},
{
title: "Queries route with empty value and no parameter in request, should not match",
route: new(Route).Queries("foo", ""),
request: newRequest("GET", "http://localhost"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with empty value and empty parameter in request, should match",
route: new(Route).Queries("foo", ""),
request: newRequest("GET", "http://localhost?foo="),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: true,
},
{
title: "Queries route with overlapping value, should not match",
route: new(Route).Queries("foo", "bar"),
request: newRequest("GET", "http://localhost?foo=barfoo"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with no parameter in request, should not match",
route: new(Route).Queries("foo", "{bar}"),
request: newRequest("GET", "http://localhost"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with empty parameter in request, should match",
route: new(Route).Queries("foo", "{bar}"),
request: newRequest("GET", "http://localhost?foo="),
vars: map[string]string{"foo": ""},
host: "",
path: "",
shouldMatch: true,
},
}
for _, test := range tests {
@@ -737,39 +593,6 @@ func TestMatcherFunc(t *testing.T) {
}
}
func TestBuildVarsFunc(t *testing.T) {
tests := []routeTest{
{
title: "BuildVarsFunc set on route",
route: new(Route).Path(`/111/{v1:\d}{v2:.*}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
vars["v1"] = "3"
vars["v2"] = "a"
return vars
}),
request: newRequest("GET", "http://localhost/111/2"),
path: "/111/3a",
shouldMatch: true,
},
{
title: "BuildVarsFunc set on route and parent route",
route: new(Route).PathPrefix(`/{v1:\d}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
vars["v1"] = "2"
return vars
}).Subrouter().Path(`/{v2:\w}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
vars["v2"] = "b"
return vars
}),
request: newRequest("GET", "http://localhost/1/a"),
path: "/2/b",
shouldMatch: true,
},
}
for _, test := range tests {
testRoute(t, test)
}
}
func TestSubRouter(t *testing.T) {
subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter()
subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter()
@@ -909,81 +732,6 @@ func TestStrictSlash(t *testing.T) {
}
}
func TestWalkSingleDepth(t *testing.T) {
r0 := NewRouter()
r1 := NewRouter()
r2 := NewRouter()
r0.Path("/g")
r0.Path("/o")
r0.Path("/d").Handler(r1)
r0.Path("/r").Handler(r2)
r0.Path("/a")
r1.Path("/z")
r1.Path("/i")
r1.Path("/l")
r1.Path("/l")
r2.Path("/i")
r2.Path("/l")
r2.Path("/l")
paths := []string{"g", "o", "r", "i", "l", "l", "a"}
depths := []int{0, 0, 0, 1, 1, 1, 0}
i := 0
err := r0.Walk(func(route *Route, router *Router, ancestors []*Route) error {
matcher := route.matchers[0].(*routeRegexp)
if matcher.template == "/d" {
return SkipRouter
}
if len(ancestors) != depths[i] {
t.Errorf(`Expected depth of %d at i = %d; got "%s"`, depths[i], i, len(ancestors))
}
if matcher.template != "/"+paths[i] {
t.Errorf(`Expected "/%s" at i = %d; got "%s"`, paths[i], i, matcher.template)
}
i++
return nil
})
if err != nil {
panic(err)
}
if i != len(paths) {
t.Errorf("Expected %d routes, found %d", len(paths), i)
}
}
func TestWalkNested(t *testing.T) {
router := NewRouter()
g := router.Path("/g").Subrouter()
o := g.PathPrefix("/o").Subrouter()
r := o.PathPrefix("/r").Subrouter()
i := r.PathPrefix("/i").Subrouter()
l1 := i.PathPrefix("/l").Subrouter()
l2 := l1.PathPrefix("/l").Subrouter()
l2.Path("/a")
paths := []string{"/g", "/g/o", "/g/o/r", "/g/o/r/i", "/g/o/r/i/l", "/g/o/r/i/l/l", "/g/o/r/i/l/l/a"}
idx := 0
err := router.Walk(func(route *Route, router *Router, ancestors []*Route) error {
path := paths[idx]
tpl := route.regexp.path.template
if tpl != path {
t.Errorf(`Expected %s got %s`, path, tpl)
}
idx++
return nil
})
if err != nil {
panic(err)
}
if idx != len(paths) {
t.Errorf("Expected %d routes, found %d", len(paths), idx)
}
}
// ----------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------