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

Function TestGlobalResolversOption

caddyconfig/httpcaddyfile/options_test.go:70–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestGlobalResolversOption(t *testing.T) {
71 tests := []struct {
72 name string
73 input string
74 expectResolvers []string
75 expectError bool
76 }{
77 {
78 name: "single resolver",
79 input: `{
80 tls_resolvers 1.1.1.1
81 }
82 example.com {
83 }`,
84 expectResolvers: []string{"1.1.1.1"},
85 expectError: false,
86 },
87 {
88 name: "two resolvers",
89 input: `{
90 tls_resolvers 1.1.1.1 8.8.8.8
91 }
92 example.com {
93 }`,
94 expectResolvers: []string{"1.1.1.1", "8.8.8.8"},
95 expectError: false,
96 },
97 {
98 name: "multiple resolvers",
99 input: `{
100 tls_resolvers 1.1.1.1 8.8.8.8 9.9.9.9
101 }
102 example.com {
103 }`,
104 expectResolvers: []string{"1.1.1.1", "8.8.8.8", "9.9.9.9"},
105 expectError: false,
106 },
107 {
108 name: "no resolvers specified",
109 input: `{
110 }
111 example.com {
112 }`,
113 expectResolvers: nil,
114 expectError: false,
115 },
116 }
117
118 for _, tc := range tests {
119 t.Run(tc.name, func(t *testing.T) {
120 adapter := caddyfile.Adapter{
121 ServerType: ServerType{},
122 }
123
124 out, _, err := adapter.Adapt([]byte(tc.input), nil)
125
126 if (err != nil) != tc.expectError {
127 t.Errorf("error expectation failed. Expected error: %v, got: %v", tc.expectError, err)

Callers

nothing calls this directly

Calls 1

AdaptMethod · 0.95

Tested by

no test coverage detected