Debian Codegraph @

errcapture/do_test.go

raw symbols SCIP
1 // Copyright (c) The EfficientGo Authors.
2 // Licensed under the Apache License 2.0.
3
4 // Initially copied from Thanos
5 //
6 // Copyright (c) The Thanos Authors.
7 // Licensed under the Apache License 2.0.
8
9 package errcapturescip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/
10
11 import (
12 "ioscip-go gomod github.com/golang/go/src go1.17 io/"
13 "testingscip-go gomod github.com/golang/go/src go1.17 testing/"
14
15 "github.com/efficientgo/core/errorsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/"
16 )
17
18 type testCloserscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser# struct {
19 errscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#err. error
20 }
21
22 func (c testCloserscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#) Closescip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#Close().() error {
23 return c.errscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#err.
24 }
25
26 func TestDoscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/TestDo().(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) {
27 for _, tcase := range []struct {
28 err error
29 closer ioscip-go gomod github.com/golang/go/src go1.17 io/.Closerscip-go gomod github.com/golang/go/src go1.17 io/Closer#
30
31 expectedErrStr string
32 }{
33 {
34 err: nil,
35 closer: testCloserscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#{errscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#err.: nil},
36 expectedErrStr: "",
37 },
38 {
39 err: errorsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/.Newscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/New().("test"),
40 closer: testCloserscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#{errscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#err.: nil},
41 expectedErrStr: "test",
42 },
43 {
44 err: nil,
45 closer: testCloserscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#{errscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#err.: errorsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/.Newscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/New().("test")},
46 expectedErrStr: "close: test",
47 },
48 {
49 err: errorsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/.Newscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/New().("test"),
50 closer: testCloserscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#{errscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/testCloser#err.: errorsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/.Newscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/New().("test")},
51 expectedErrStr: "2 errors: test; close: test",
52 },
53 } {
54 if ok := t.Runscip-go gomod github.com/golang/go/src go1.17 testing/T#Run().("", func(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) {
55 ret := tcase.err
56 Doscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errcapture`/Do().(&ret, tcase.closer.Closescip-go gomod github.com/golang/go/src go1.17 io/Closer#Close()., "close")
57
58 if tcase.expectedErrStr == "" {
59 if ret != nil {
60 t.Errorscip-go gomod github.com/golang/go/src go1.17 testing/common#Error().("Expected error to be nil")
61 t.Failscip-go gomod github.com/golang/go/src go1.17 testing/common#Fail().()
62 }
63 } else {
64 if ret == nil {
65 t.Errorscip-go gomod github.com/golang/go/src go1.17 testing/common#Error().("Expected error to be not nil")
66 t.Failscip-go gomod github.com/golang/go/src go1.17 testing/common#Fail().()
67 }
68
69 if tcase.expectedErrStr != ret.Error() {
70 t.Errorfscip-go gomod github.com/golang/go/src go1.17 testing/common#Errorf().("%s != %s", tcase.expectedErrStr, ret.Error())
71 t.Failscip-go gomod github.com/golang/go/src go1.17 testing/common#Fail().()
72 }
73 }
74
75 }); !ok {
76 return
77 }
78 }
79 }