github.com/cayleygraph/cayley@v0.7.7/graph/quadwriter_test.go (about) 1 package graph 2 3 import ( 4 "errors" 5 "testing" 6 ) 7 8 func TestIsQuadExist(t *testing.T) { 9 tests := []struct { 10 Err error 11 Matches bool 12 }{ 13 {Err: nil, Matches: false}, 14 {Err: errors.New("foo"), Matches: false}, 15 {Err: ErrQuadExists, Matches: true}, 16 {Err: &DeltaError{Err: errors.New("foo")}, Matches: false}, 17 {Err: &DeltaError{Err: ErrQuadExists}, Matches: true}, 18 } 19 20 for i, test := range tests { 21 if match := IsQuadExist(test.Err); test.Matches != match { 22 t.Errorf("%d> unexpected match: %t", i, match) 23 } 24 } 25 } 26 27 func TestIsQuadNotExist(t *testing.T) { 28 tests := []struct { 29 Err error 30 Matches bool 31 }{ 32 {Err: nil, Matches: false}, 33 {Err: errors.New("foo"), Matches: false}, 34 {Err: ErrQuadNotExist, Matches: true}, 35 {Err: &DeltaError{Err: errors.New("foo")}, Matches: false}, 36 {Err: &DeltaError{Err: ErrQuadNotExist}, Matches: true}, 37 } 38 39 for i, test := range tests { 40 if match := IsQuadNotExist(test.Err); test.Matches != match { 41 t.Errorf("%d> unexpected match: %t", i, match) 42 } 43 } 44 } 45 46 func TestIsInvalidAction(t *testing.T) { 47 tests := []struct { 48 Err error 49 Matches bool 50 }{ 51 {Err: nil, Matches: false}, 52 {Err: errors.New("foo"), Matches: false}, 53 {Err: ErrInvalidAction, Matches: true}, 54 {Err: &DeltaError{Err: errors.New("foo")}, Matches: false}, 55 {Err: &DeltaError{Err: ErrInvalidAction}, Matches: true}, 56 } 57 58 for i, test := range tests { 59 if match := IsInvalidAction(test.Err); test.Matches != match { 60 t.Errorf("%d> unexpected match: %t", i, match) 61 } 62 } 63 }