(t *testing.T, test routeTest)
| 1785 | } |
| 1786 | |
| 1787 | func 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 { |
no test coverage detected