OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package errors | 5 package errors |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "fmt" | 9 "fmt" |
10 "testing" | 10 "testing" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } { | 60 } { |
61 Convey(fmt.Sprintf(`Registers false for %T %v`, err, err
), func() { | 61 Convey(fmt.Sprintf(`Registers false for %T %v`, err, err
), func() { |
62 So(Any(err, filter), ShouldBeFalse) | 62 So(Any(err, filter), ShouldBeFalse) |
63 }) | 63 }) |
64 } | 64 } |
65 | 65 |
66 for _, err := range []error{ | 66 for _, err := range []error{ |
67 testErr, | 67 testErr, |
68 MultiError{errors.New("other error"), MultiError{testErr
, nil}}, | 68 MultiError{errors.New("other error"), MultiError{testErr
, nil}}, |
69 Annotate(testErr).Reason("error test").Err(), | 69 Annotate(testErr).Reason("error test").Err(), |
70 WrapTransient(MultiError{WrapTransient(testErr), nil, er
rors.New("other error")}), | |
71 } { | 70 } { |
72 Convey(fmt.Sprintf(`Registers true for %T %v`, err, err)
, func() { | 71 Convey(fmt.Sprintf(`Registers true for %T %v`, err, err)
, func() { |
73 So(Any(err, filter), ShouldBeTrue) | 72 So(Any(err, filter), ShouldBeTrue) |
74 }) | 73 }) |
75 } | 74 } |
76 }) | 75 }) |
77 } | 76 } |
78 | 77 |
79 func TestContains(t *testing.T) { | 78 func TestContains(t *testing.T) { |
80 t.Parallel() | 79 t.Parallel() |
81 | 80 |
82 Convey(`Testing the Contains function for a sentinel error`, t, func() { | 81 Convey(`Testing the Contains function for a sentinel error`, t, func() { |
83 sentinel := errors.New("test error") | 82 sentinel := errors.New("test error") |
84 | 83 |
85 for _, err := range []error{ | 84 for _, err := range []error{ |
86 nil, | 85 nil, |
87 errors.New("foo"), | 86 errors.New("foo"), |
88 errors.New("test error"), | 87 errors.New("test error"), |
89 } { | 88 } { |
90 Convey(fmt.Sprintf(`Registers false for %T %v`, err, err
), func() { | 89 Convey(fmt.Sprintf(`Registers false for %T %v`, err, err
), func() { |
91 So(Contains(err, sentinel), ShouldBeFalse) | 90 So(Contains(err, sentinel), ShouldBeFalse) |
92 }) | 91 }) |
93 } | 92 } |
94 | 93 |
95 for _, err := range []error{ | 94 for _, err := range []error{ |
96 sentinel, | 95 sentinel, |
97 MultiError{errors.New("other error"), MultiError{sentine
l, nil}}, | 96 MultiError{errors.New("other error"), MultiError{sentine
l, nil}}, |
98 WrapTransient(MultiError{WrapTransient(sentinel), nil, e
rrors.New("other error")}), | |
99 } { | 97 } { |
100 Convey(fmt.Sprintf(`Registers true for %T %v`, err, err)
, func() { | 98 Convey(fmt.Sprintf(`Registers true for %T %v`, err, err)
, func() { |
101 So(Contains(err, sentinel), ShouldBeTrue) | 99 So(Contains(err, sentinel), ShouldBeTrue) |
102 }) | 100 }) |
103 } | 101 } |
104 }) | 102 }) |
105 } | 103 } |
OLD | NEW |