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

Function TestHost

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

Source from the content-addressed store, hash-verified

53}
54
55func TestHost(t *testing.T) {
56
57 tests := []routeTest{
58 {
59 title: "Host route match",
60 route: new(Route).Host("aaa.bbb.ccc"),
61 request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
62 vars: map[string]string{},
63 host: "aaa.bbb.ccc",
64 path: "",
65 shouldMatch: true,
66 },
67 {
68 title: "Host route, wrong host in request URL",
69 route: new(Route).Host("aaa.bbb.ccc"),
70 request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
71 vars: map[string]string{},
72 host: "aaa.bbb.ccc",
73 path: "",
74 shouldMatch: false,
75 },
76 {
77 title: "Host route with port, match",
78 route: new(Route).Host("aaa.bbb.ccc:1234"),
79 request: newRequest("GET", "http://aaa.bbb.ccc:1234/111/222/333"),
80 vars: map[string]string{},
81 host: "aaa.bbb.ccc:1234",
82 path: "",
83 shouldMatch: true,
84 },
85 {
86 title: "Host route with port, wrong port in request URL",
87 route: new(Route).Host("aaa.bbb.ccc:1234"),
88 request: newRequest("GET", "http://aaa.bbb.ccc:9999/111/222/333"),
89 vars: map[string]string{},
90 host: "aaa.bbb.ccc:1234",
91 path: "",
92 shouldMatch: false,
93 },
94 {
95 title: "Host route, match with host in request header",
96 route: new(Route).Host("aaa.bbb.ccc"),
97 request: newRequestHost("GET", "/111/222/333", "aaa.bbb.ccc"),
98 vars: map[string]string{},
99 host: "aaa.bbb.ccc",
100 path: "",
101 shouldMatch: true,
102 },
103 {
104 title: "Host route, wrong host in request header",
105 route: new(Route).Host("aaa.bbb.ccc"),
106 request: newRequestHost("GET", "/111/222/333", "aaa.222.ccc"),
107 vars: map[string]string{},
108 host: "aaa.bbb.ccc",
109 path: "",
110 shouldMatch: false,
111 },
112 {

Callers

nothing calls this directly

Calls 5

newRequestFunction · 0.85
newRequestHostFunction · 0.85
testRouteFunction · 0.85
testTemplateFunction · 0.85
HostMethod · 0.45

Tested by

no test coverage detected