github.com/mailgun/holster/v4@v4.20.0/errors/go113_test.go (about) 1 //go:build go1.13 2 // +build go1.13 3 4 package errors 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestIs(t *testing.T) { 14 target := New("wrapped") 15 16 tests := []struct { 17 name string 18 target error 19 err error 20 }{ 21 { 22 name: "holster_wrap", 23 target: target, 24 err: Wrap(target, "some reason"), 25 }, 26 { 27 name: "holster_double_wrap", 28 target: target, 29 err: Wrap(Wrap(target, "reason 2"), "reason 1"), 30 }, 31 { 32 name: "holster_triple_wrap", 33 target: target, 34 err: Wrap(Wrap(Wrap(target, "reason 3"), "reason 2"), "reason 1"), 35 }, 36 { 37 name: "holster_triple_wrapf", 38 target: target, 39 err: Wrapf(Wrapf(Wrapf(target, "reason %d", 3), "reason %d", 2), "reason %d", 1), 40 }, 41 { 42 name: "std_wrap", 43 target: target, 44 err: fmt.Errorf("some reason: %w", target), 45 }, 46 { 47 name: "std_double_wrap", 48 target: target, 49 err: fmt.Errorf("reason 1: %w", fmt.Errorf("reason 2: %w", target)), 50 }, 51 } 52 53 for _, tt := range tests { 54 t.Run(tt.name, func(t *testing.T) { 55 assert.True(t, Is(tt.err, tt.target)) 56 assert.ErrorIs(t, tt.err, tt.target) 57 }) 58 } 59 }