1package interactors 2 3import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8) 9 10var trueErr1 error = errors.New("I had a rough night, and I hate the eagles man") 11var trueErr2 error = errors.New("This is what happens when you find a stranger in the Alps") 12 13func TestExistingErrorOrTT(t *testing.T) { 14 assert.Equal( 15 t, 16 trueErr1, 17 ExistingErrorOr( 18 trueErr1, 19 func() error { 20 return trueErr2 21 }, 22 ), 23 "Should return first true", 24 ) 25} 26 27func TestExistingErrorOrTF(t *testing.T) { 28 assert.Equal( 29 t, 30 trueErr1, 31 ExistingErrorOr( 32 trueErr1, 33 func() error { 34 panic("Short circuit before I blow up") 35 return nil 36 }, 37 ), 38 "Should short circuit true", 39 ) 40} 41 42func TestExistingErrorOrFT(t *testing.T) { 43 assert.Equal( 44 t, 45 trueErr2, 46 ExistingErrorOr( 47 nil, 48 func() error { 49 return trueErr2 50 }, 51 ), 52 "Function should be evaluated to an error", 53 ) 54} 55 56func TestExistingErrorOrFF(t *testing.T) { 57 assert.Equal( 58 t, 59 nil, 60 ExistingErrorOr( 61 nil, 62 func() error { 63 return nil 64 }, 65 ), 66 "Should evaluate to nil", 67 ) 68} 69 70func TestAnyErrorPositive(t *testing.T) { 71 assert.Equal( 72 t, 73 trueErr1, 74 AnyError(nil, trueErr1, nil), 75 "Should return existing error", 76 ) 77} 78 79func TestAnyErrorNegative(t *testing.T) { 80 assert.Equal( 81 t, 82 nil, 83 AnyError(nil, nil, nil), 84 "Should not return an error", 85 ) 86} 87