This test should work only for go 1.13 and latter
(t *testing.T)
| 9 | |
| 10 | // This test should work only for go 1.13 and latter |
| 11 | func TestIs113(t *testing.T) { |
| 12 | custErr := errorWithCustomIs{ |
| 13 | Key: "TestForFun", |
| 14 | Err: io.EOF, |
| 15 | } |
| 16 | |
| 17 | shouldMatch := errorWithCustomIs{ |
| 18 | Key: "TestForFun", |
| 19 | } |
| 20 | |
| 21 | shouldNotMatch := errorWithCustomIs{Key: "notOk"} |
| 22 | |
| 23 | if !Is(custErr, shouldMatch) { |
| 24 | t.Errorf("custErr is not a TestForFun customError") |
| 25 | } |
| 26 | |
| 27 | if Is(custErr, shouldNotMatch) { |
| 28 | t.Errorf("custErr is a notOk customError") |
| 29 | } |
| 30 | |
| 31 | if !Is(custErr, New(shouldMatch)) { |
| 32 | t.Errorf("custErr is not a New(TestForFun customError)") |
| 33 | } |
| 34 | |
| 35 | if Is(custErr, New(shouldNotMatch)) { |
| 36 | t.Errorf("custErr is a New(notOk customError)") |
| 37 | } |
| 38 | |
| 39 | if !Is(New(custErr), shouldMatch) { |
| 40 | t.Errorf("New(custErr) is not a TestForFun customError") |
| 41 | } |
| 42 | |
| 43 | if Is(New(custErr), shouldNotMatch) { |
| 44 | t.Errorf("New(custErr) is a notOk customError") |
| 45 | } |
| 46 | |
| 47 | if !Is(New(custErr), New(shouldMatch)) { |
| 48 | t.Errorf("New(custErr) is not a New(TestForFun customError)") |
| 49 | } |
| 50 | |
| 51 | if Is(New(custErr), New(shouldNotMatch)) { |
| 52 | t.Errorf("New(custErr) is a New(notOk customError)") |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | type errorWithCustomIs struct { |
| 57 | Key string |