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

Function TestImportErrorLine

caddyconfig/httpcaddyfile/builtins_test.go:235–296  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

233}
234
235func TestImportErrorLine(t *testing.T) {
236 for i, tc := range []struct {
237 input string
238 errorFunc func(err error) bool
239 }{
240 {
241 input: `(t1) {
242 abort {args[:]}
243 }
244 :8080 {
245 import t1
246 import t1 true
247 }`,
248 errorFunc: func(err error) bool {
249 return err != nil && strings.Contains(err.Error(), "Caddyfile:6 (import t1)")
250 },
251 },
252 {
253 input: `(t1) {
254 abort {args[:]}
255 }
256 :8080 {
257 import t1 true
258 }`,
259 errorFunc: func(err error) bool {
260 return err != nil && strings.Contains(err.Error(), "Caddyfile:5 (import t1)")
261 },
262 },
263 {
264 input: `
265 import testdata/import_variadic_snippet.txt
266 :8080 {
267 import t1 true
268 }`,
269 errorFunc: func(err error) bool {
270 return err == nil
271 },
272 },
273 {
274 input: `
275 import testdata/import_variadic_with_import.txt
276 :8080 {
277 import t1 true
278 import t2 true
279 }`,
280 errorFunc: func(err error) bool {
281 return err == nil
282 },
283 },
284 } {
285 adapter := caddyfile.Adapter{
286 ServerType: ServerType{},
287 }
288
289 _, _, err := adapter.Adapt([]byte(tc.input), nil)
290
291 if !tc.errorFunc(err) {
292 t.Errorf("Test %d error expectation failed, got %s", i, err)

Callers

nothing calls this directly

Calls 2

AdaptMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected