github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/pkg/errors/errors_test.go (about) 1 package errors 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestErrors(t *testing.T) { 10 t.Parallel() 11 12 require := require.New(t) 13 14 var ( 15 ErrNil error 16 ErrNew = New("new error") 17 ) 18 19 require.Nil(Wrap(ErrNil, "wrap")) 20 require.Nil(Wrapf(ErrNil, "wrap %s", "1")) 21 22 for _, tt := range []struct { 23 err error 24 wantText string 25 }{ 26 {ErrNew, "new error"}, 27 {Wrap(ErrNew, "wrap"), "wrap: new error"}, 28 {Wrap(Wrap(ErrNew, "wrap"), "wrap1"), "wrap1: wrap: new error"}, 29 {Wrapf(ErrNew, "format %d", 15), "format 15: new error"}, 30 {Errorf("some message: %w", ErrNew), "some message: new error"}, 31 } { 32 got := Is(tt.err, ErrNew) 33 require.True(got) 34 require.Equal(tt.wantText, tt.err.Error()) 35 } 36 }