MCPcopy
hub / github.com/grafana/dskit / TestRecoverableT

Function TestRecoverableT

test/recoverable_t_test.go:11–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestRecoverableT(t *testing.T) {
12 t.Run("FailNow marks test as failed", func(t *testing.T) {
13 inner := &mockTB{}
14 rt := NewRecoverableT(inner)
15 defer rt.Recover()
16
17 rt.FailNow()
18
19 assert.True(t, inner.failed, "expected underlying TB to be marked as failed")
20 })
21
22 t.Run("Fatal marks test as failed", func(t *testing.T) {
23 inner := &mockTB{}
24 rt := NewRecoverableT(inner)
25 defer rt.Recover()
26
27 rt.Fatal("something went wrong")
28
29 assert.True(t, inner.failed, "expected underlying TB to be marked as failed")
30 assert.Contains(t, inner.lastError, "something went wrong")
31 })
32
33 t.Run("Fatalf marks test as failed", func(t *testing.T) {
34 inner := &mockTB{}
35 rt := NewRecoverableT(inner)
36 defer rt.Recover()
37
38 rt.Fatalf("value is %d", 42)
39
40 assert.True(t, inner.failed, "expected underlying TB to be marked as failed")
41 assert.Contains(t, inner.lastError, "value is 42")
42 })
43
44 t.Run("Recover catches FailNow", func(t *testing.T) {
45 inner := &mockTB{}
46 rt := NewRecoverableT(inner)
47
48 func() {
49 defer rt.Recover()
50 rt.FailNow()
51 t.Fatal("should not reach here")
52 }()
53
54 assert.True(t, inner.failed)
55 })
56
57 t.Run("Recover re-raises non-sentinel panic", func(t *testing.T) {
58 inner := &mockTB{}
59 rt := NewRecoverableT(inner)
60
61 assert.PanicsWithValue(t, "real panic", func() {
62 defer rt.Recover()
63 panic("real panic")
64 })
65 })
66
67 t.Run("RecoverError returns ErrTestFailed", func(t *testing.T) {
68 inner := &mockTB{}

Callers

nothing calls this directly

Calls 8

RecoverMethod · 0.95
FailNowMethod · 0.95
FatalMethod · 0.95
FatalfMethod · 0.95
RecoverErrorMethod · 0.95
NewRecoverableTFunction · 0.85
RunMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected