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

Function TestCloseWithErrCapture

runutil/runutil_test.go:70–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68type testCloser = fakeCloser
69
70func TestCloseWithErrCapture(t *testing.T) {
71 for _, tcase := range []struct {
72 err error
73 closer io.Closer
74
75 expectedErrStr string
76 }{
77 {
78 err: nil,
79 closer: testCloser{err: nil},
80 expectedErrStr: "",
81 },
82 {
83 err: errors.New("test"),
84 closer: testCloser{err: nil},
85 expectedErrStr: "test",
86 },
87 {
88 err: nil,
89 closer: testCloser{err: errors.New("test")},
90 expectedErrStr: "close: test",
91 },
92 {
93 err: errors.New("test"),
94 closer: testCloser{err: errors.New("test")},
95 expectedErrStr: "2 errors: test; close: test",
96 },
97 } {
98 t.Run(tcase.expectedErrStr, func(t *testing.T) {
99 ret := tcase.err
100 CloseWithErrCapture(&ret, tcase.closer, "close")
101
102 if tcase.expectedErrStr == "" {
103 assert.NoError(t, ret)
104 } else {
105 require.Error(t, ret)
106 assert.Equal(t, tcase.expectedErrStr, ret.Error())
107 }
108 })
109 }
110}
111
112type loggerCapturer struct {
113 // WasCalled is true if the Log() function has been called.

Callers

nothing calls this directly

Calls 4

CloseWithErrCaptureFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected