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

Function TestDispenser_ArgErr_Err

caddyconfig/caddyfile/dispenser_test.go:337–373  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

335}
336
337func TestDispenser_ArgErr_Err(t *testing.T) {
338 input := `dir1 {
339 }
340 dir2 arg1 arg2`
341 d := NewTestDispenser(input)
342
343 d.cursor = 1 // {
344
345 if err := d.ArgErr(); err == nil || !strings.Contains(err.Error(), "{") {
346 t.Errorf("ArgErr(): Expected an error message with { in it, but got '%v'", err)
347 }
348
349 d.cursor = 5 // arg2
350
351 if err := d.ArgErr(); err == nil || !strings.Contains(err.Error(), "arg2") {
352 t.Errorf("ArgErr(): Expected an error message with 'arg2' in it; got '%v'", err)
353 }
354
355 err := d.Err("foobar")
356 if err == nil {
357 t.Fatalf("Err(): Expected an error, got nil")
358 }
359
360 if !strings.Contains(err.Error(), "Testfile:3") {
361 t.Errorf("Expected error message with filename:line in it; got '%v'", err)
362 }
363
364 if !strings.Contains(err.Error(), "foobar") {
365 t.Errorf("Expected error message with custom message in it ('foobar'); got '%v'", err)
366 }
367
368 ErrBarIsFull := errors.New("bar is full")
369 bookingError := d.Errf("unable to reserve: %w", ErrBarIsFull)
370 if !errors.Is(bookingError, ErrBarIsFull) {
371 t.Errorf("Errf(): should be able to unwrap the error chain")
372 }
373}

Callers

nothing calls this directly

Calls 5

NewTestDispenserFunction · 0.85
ArgErrMethod · 0.80
ErrMethod · 0.80
ErrfMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected