MCPcopy
hub / github.com/labstack/echo / TestVirtualHostHandler

Function TestVirtualHostHandler

vhost_test.go:13–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestVirtualHostHandler(t *testing.T) {
14 okHandler := func(c *Context) error { return c.String(http.StatusOK, http.StatusText(http.StatusOK)) }
15 teapotHandler := func(c *Context) error { return c.String(http.StatusTeapot, http.StatusText(http.StatusTeapot)) }
16 acceptHandler := func(c *Context) error { return c.String(http.StatusAccepted, http.StatusText(http.StatusAccepted)) }
17 teapotMiddleware := MiddlewareFunc(func(next HandlerFunc) HandlerFunc { return teapotHandler })
18
19 ok := New()
20 ok.GET("/", okHandler)
21 ok.GET("/foo", okHandler)
22
23 teapot := New()
24 teapot.GET("/", teapotHandler)
25 teapot.GET("/foo", teapotHandler)
26
27 middle := New()
28 middle.Use(teapotMiddleware)
29 middle.GET("/", okHandler)
30 middle.GET("/foo", okHandler)
31
32 virtualHosts := NewVirtualHostHandler(map[string]*Echo{
33 "ok.com": ok,
34 "teapot.com": teapot,
35 "middleware.com": middle,
36 })
37 virtualHosts.GET("/", acceptHandler)
38 virtualHosts.GET("/foo", acceptHandler)
39
40 var testCases = []struct {
41 name string
42 whenHost string
43 whenPath string
44 expectBody string
45 expectStatus int
46 }{
47 {
48 name: "No Host Root",
49 whenHost: "",
50 whenPath: "/",
51 expectBody: http.StatusText(http.StatusAccepted),
52 expectStatus: http.StatusAccepted,
53 },
54 {
55 name: "No Host Foo",
56 whenHost: "",
57 whenPath: "/foo",
58 expectBody: http.StatusText(http.StatusAccepted),
59 expectStatus: http.StatusAccepted,
60 },
61 {
62 name: "OK Host Root",
63 whenHost: "ok.com",
64 whenPath: "/",
65 expectBody: http.StatusText(http.StatusOK),
66 expectStatus: http.StatusOK,
67 },
68 {
69 name: "OK Host Foo",
70 whenHost: "ok.com",

Callers

nothing calls this directly

Calls 7

MiddlewareFuncFuncType · 0.85
NewFunction · 0.85
NewVirtualHostHandlerFunction · 0.85
ServeHTTPMethod · 0.80
StringMethod · 0.45
GETMethod · 0.45
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…