MCPcopy
hub / github.com/gorilla/mux / testRoute

Function testRoute

mux_test.go:1787–1882  ·  view source on GitHub ↗
(t *testing.T, test routeTest)

Source from the content-addressed store, hash-verified

1785}
1786
1787func testRoute(t *testing.T, test routeTest) {
1788 request := test.request
1789 route := test.route
1790 vars := test.vars
1791 shouldMatch := test.shouldMatch
1792 query := test.query
1793 shouldRedirect := test.shouldRedirect
1794 uri := url.URL{
1795 Scheme: test.scheme,
1796 Host: test.host,
1797 Path: test.path,
1798 }
1799 if uri.Scheme == "" {
1800 uri.Scheme = "http"
1801 }
1802
1803 var match RouteMatch
1804 ok := route.Match(request, &match)
1805 if ok != shouldMatch {
1806 msg := "Should match"
1807 if !shouldMatch {
1808 msg = "Should not match"
1809 }
1810 t.Errorf("(%v) %v:\nRoute: %#v\nRequest: %#v\nVars: %v\n", test.title, msg, route, request, vars)
1811 return
1812 }
1813 if shouldMatch {
1814 if vars != nil && !stringMapEqual(vars, match.Vars) {
1815 t.Errorf("(%v) Vars not equal: expected %v, got %v", test.title, vars, match.Vars)
1816 return
1817 }
1818 if test.scheme != "" {
1819 u, err := route.URL(mapToPairs(match.Vars)...)
1820 if err != nil {
1821 t.Fatalf("(%v) URL error: %v -- %v", test.title, err, getRouteTemplate(route))
1822 }
1823 if uri.Scheme != u.Scheme {
1824 t.Errorf("(%v) URLScheme not equal: expected %v, got %v", test.title, uri.Scheme, u.Scheme)
1825 return
1826 }
1827 }
1828 if test.host != "" {
1829 u, err := test.route.URLHost(mapToPairs(match.Vars)...)
1830 if err != nil {
1831 t.Fatalf("(%v) URLHost error: %v -- %v", test.title, err, getRouteTemplate(route))
1832 }
1833 if uri.Scheme != u.Scheme {
1834 t.Errorf("(%v) URLHost scheme not equal: expected %v, got %v -- %v", test.title, uri.Scheme, u.Scheme, getRouteTemplate(route))
1835 return
1836 }
1837 if uri.Host != u.Host {
1838 t.Errorf("(%v) URLHost host not equal: expected %v, got %v -- %v", test.title, uri.Host, u.Host, getRouteTemplate(route))
1839 return
1840 }
1841 }
1842 if test.path != "" {
1843 u, err := route.URLPath(mapToPairs(match.Vars)...)
1844 if err != nil {

Callers 13

TestHostFunction · 0.85
TestPathFunction · 0.85
TestPathPrefixFunction · 0.85
TestSchemeHostPathFunction · 0.85
TestHeadersFunction · 0.85
TestMethodsFunction · 0.85
TestSchemesFunction · 0.85
TestMatcherFuncFunction · 0.85
TestBuildVarsFuncFunction · 0.85
TestSubRouterFunction · 0.85
TestStrictSlashFunction · 0.85
TestUseEncodedPathFunction · 0.85

Calls 7

stringMapEqualFunction · 0.85
mapToPairsFunction · 0.85
getRouteTemplateFunction · 0.85
URLMethod · 0.80
URLHostMethod · 0.80
URLPathMethod · 0.80
MatchMethod · 0.65

Tested by

no test coverage detected