MCPcopy
hub / github.com/caddyserver/caddy / TestHostMatcher

Function TestHostMatcher

modules/caddyhttp/matchers_test.go:30–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestHostMatcher(t *testing.T) {
31 err := os.Setenv("GO_BENCHMARK_DOMAIN", "localhost")
32 if err != nil {
33 t.Errorf("error while setting up environment: %v", err)
34 }
35
36 for i, tc := range []struct {
37 match MatchHost
38 input string
39 expect bool
40 }{
41 {
42 match: MatchHost{},
43 input: "example.com",
44 expect: false,
45 },
46 {
47 match: MatchHost{"example.com"},
48 input: "example.com",
49 expect: true,
50 },
51 {
52 match: MatchHost{"EXAMPLE.COM"},
53 input: "example.com",
54 expect: true,
55 },
56 {
57 match: MatchHost{"example.com"},
58 input: "EXAMPLE.COM",
59 expect: true,
60 },
61 {
62 match: MatchHost{"example.com"},
63 input: "foo.example.com",
64 expect: false,
65 },
66 {
67 match: MatchHost{"example.com"},
68 input: "EXAMPLE.COM",
69 expect: true,
70 },
71 {
72 match: MatchHost{"foo.example.com"},
73 input: "foo.example.com",
74 expect: true,
75 },
76 {
77 match: MatchHost{"foo.example.com"},
78 input: "bar.example.com",
79 expect: false,
80 },
81 {
82 match: MatchHost{"éxàmplê.com"},
83 input: "xn--xmpl-0na6cm.com",
84 expect: true,
85 },
86 {
87 match: MatchHost{"*.example.com"},

Callers

nothing calls this directly

Calls 3

WithValueMethod · 0.80
ProvisionMethod · 0.65
MatchWithErrorMethod · 0.65

Tested by

no test coverage detected