mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Also: - build a custom URL matcher to cope with container image names having a encoded forward slash in them. - escape node ids in the UI when constructing URLs. - add a test which fetches all the nodes of all topologies, and update report fixture to have slash in container image names.
31 lines
749 B
Go
31 lines
749 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
type v map[string]string
|
|
|
|
func TestURLMatcher(t *testing.T) {
|
|
test := func(pattern, path string, match bool, vars v) {
|
|
routeMatch := &mux.RouteMatch{}
|
|
if URLMatcher(pattern)(&http.Request{RequestURI: path}, routeMatch) != match {
|
|
t.Fatalf("'%s' '%s'", pattern, path)
|
|
}
|
|
if match && !reflect.DeepEqual(v(routeMatch.Vars), vars) {
|
|
t.Fatalf("%v != %v", v(routeMatch.Vars), vars)
|
|
}
|
|
}
|
|
|
|
test("/a/b/c", "/a/b/c", true, v{})
|
|
test("/a/b/c", "/c/b/a", false, v{})
|
|
test("/{a}/b/c", "/b/b/c", true, v{"a": "b"})
|
|
test("/{a}/b/c", "/b/b/b", false, v{})
|
|
test("/a/b/{c}", "/a/b/b", true, v{"c": "b"})
|
|
test("/a/b/{c}", "/a/b/b%2Fb", true, v{"c": "b/b"})
|
|
}
|