github.com/replicatedhq/ship@v0.55.0/pkg/util/warnings/warn_test.go (about) 1 package warnings 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/pkg/errors" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestStripStackIfWarning(t *testing.T) { 12 tests := []struct { 13 name string 14 in error 15 want string 16 }{ 17 { 18 name: "no stack", 19 in: fmt.Errorf("fake"), 20 want: "fake", 21 }, 22 { 23 name: "no stack pkgerror", 24 in: errors.New("lol nope"), 25 want: "lol nope", 26 }, 27 { 28 name: "pkgerror with stack", 29 in: errors.Wrap(errors.New("lol nope"), "get something"), 30 want: "get something: lol nope", 31 }, 32 { 33 name: "warning without stack", 34 in: warning{msg: "lol nope"}, 35 want: "lol nope", 36 }, 37 { 38 name: "warning with stack", 39 in: errors.Wrap(warning{msg: "lol nope"}, "get something"), 40 want: "lol nope", 41 }, 42 } 43 for _, test := range tests { 44 t.Run(test.name, func(t *testing.T) { 45 require.Equal(t, test.want, StripStackIfWarning(test.in).Error()) 46 }) 47 } 48 }