MCPcopy Create free account
hub / github.com/coder/slog / TestIgnoreErrorIs_Explicit

Function TestIgnoreErrorIs_Explicit

sloggers/slogtest/t_test.go:82–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestIgnoreErrorIs_Explicit(t *testing.T) {
83 t.Parallel()
84
85 tb := &fakeTB{}
86 ignored := xerrors.New("ignored")
87 notIgnored := xerrors.New("not ignored")
88 l := slogtest.Make(tb, &slogtest.Options{IgnoredErrorIs: []error{ignored}})
89
90 l.Error(bg, "ignored", slog.Error(xerrors.Errorf("test %w:", ignored)))
91 assert.Equal(t, "errors", 0, tb.errors)
92
93 l.Error(bg, "not ignored", slog.Error(xerrors.Errorf("test %w:", notIgnored)))
94 assert.Equal(t, "errors", 1, tb.errors)
95
96 l.Error(bg, "canceled", slog.Error(xerrors.Errorf("test %w:", context.Canceled)))
97 assert.Equal(t, "errors", 2, tb.errors)
98
99 l.Error(bg, "deadline", slog.Error(xerrors.Errorf("test %w:", context.DeadlineExceeded)))
100 assert.Equal(t, "errors", 3, tb.errors)
101
102 l.Error(bg, "new", slog.Error(xerrors.New("test")))
103 assert.Equal(t, "errors", 4, tb.errors)
104
105 defer func() {
106 recover()
107 assert.Equal(t, "fatals", 1, tb.fatals)
108 }()
109
110 l.Fatal(bg, "hello", slog.Error(xerrors.Errorf("test %w:", ignored)))
111}
112
113func TestIgnoreErrorFn(t *testing.T) {
114 t.Parallel()

Callers

nothing calls this directly

Calls 5

MakeFunction · 0.92
EqualFunction · 0.92
ErrorfMethod · 0.80
ErrorMethod · 0.45
FatalMethod · 0.45

Tested by

no test coverage detected