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

Function TestQueries

mux_test.go:767–1075  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

765}
766
767func TestQueries(t *testing.T) {
768 tests := []routeTest{
769 {
770 title: "Queries route, match",
771 route: new(Route).Queries("foo", "bar", "baz", "ding"),
772 request: newRequest("GET", "http://localhost?foo=bar&baz=ding"),
773 vars: map[string]string{},
774 host: "",
775 path: "",
776 query: "foo=bar&baz=ding",
777 queriesTemplate: "foo=bar,baz=ding",
778 queriesRegexp: "^foo=bar$,^baz=ding$",
779 shouldMatch: true,
780 },
781 {
782 title: "Queries route, match with a query string",
783 route: new(Route).Host("www.example.com").Path("/api").Queries("foo", "bar", "baz", "ding"),
784 request: newRequest("GET", "http://www.example.com/api?foo=bar&baz=ding"),
785 vars: map[string]string{},
786 host: "",
787 path: "",
788 query: "foo=bar&baz=ding",
789 pathTemplate: `/api`,
790 hostTemplate: `www.example.com`,
791 queriesTemplate: "foo=bar,baz=ding",
792 queriesRegexp: "^foo=bar$,^baz=ding$",
793 shouldMatch: true,
794 },
795 {
796 title: "Queries route, match with a query string out of order",
797 route: new(Route).Host("www.example.com").Path("/api").Queries("foo", "bar", "baz", "ding"),
798 request: newRequest("GET", "http://www.example.com/api?baz=ding&foo=bar"),
799 vars: map[string]string{},
800 host: "",
801 path: "",
802 query: "foo=bar&baz=ding",
803 pathTemplate: `/api`,
804 hostTemplate: `www.example.com`,
805 queriesTemplate: "foo=bar,baz=ding",
806 queriesRegexp: "^foo=bar$,^baz=ding$",
807 shouldMatch: true,
808 },
809 {
810 title: "Queries route, bad query",
811 route: new(Route).Queries("foo", "bar", "baz", "ding"),
812 request: newRequest("GET", "http://localhost?foo=bar&baz=dong"),
813 vars: map[string]string{},
814 host: "",
815 path: "",
816 queriesTemplate: "foo=bar,baz=ding",
817 queriesRegexp: "^foo=bar$,^baz=ding$",
818 shouldMatch: false,
819 },
820 {
821 title: "Queries route with pattern, match",
822 route: new(Route).Queries("foo", "{v1}"),
823 request: newRequest("GET", "http://localhost?foo=bar"),
824 vars: map[string]string{"v1": "bar"},

Callers

nothing calls this directly

Calls 8

newRequestFunction · 0.85
testTemplateFunction · 0.85
testQueriesTemplatesFunction · 0.85
testUseEscapedRouteFunction · 0.85
testQueriesRegexpFunction · 0.85
QueriesMethod · 0.45
PathMethod · 0.45
HostMethod · 0.45

Tested by

no test coverage detected