github.com/lmittmann/w3@v0.20.0/internal/cmp_test.go (about) 1 package internal 2 3 import ( 4 "fmt" 5 "io" 6 "strconv" 7 "testing" 8 9 "github.com/google/go-cmp/cmp" 10 ) 11 12 func TestEquateErrors(t *testing.T) { 13 tests := []struct { 14 A, B interface{} 15 WantEqual bool 16 }{ 17 { 18 A: fmt.Errorf("err"), 19 B: fmt.Errorf("err"), 20 WantEqual: true, 21 }, 22 { 23 A: fmt.Errorf("err: err2"), 24 B: fmt.Errorf("err: %w", fmt.Errorf("err2")), 25 WantEqual: true, 26 }, 27 { 28 A: fmt.Errorf("EOF"), 29 B: io.EOF, 30 WantEqual: true, 31 }, 32 { 33 A: fmt.Errorf("err"), 34 B: fmt.Errorf("xxx"), 35 WantEqual: false, 36 }, 37 { 38 A: fmt.Errorf("err"), 39 B: nil, 40 WantEqual: false, 41 }, 42 { 43 A: nil, 44 B: fmt.Errorf("err"), 45 WantEqual: false, 46 }, 47 } 48 49 for i, test := range tests { 50 t.Run(strconv.Itoa(i), func(t *testing.T) { 51 if gotEqual := cmp.Equal(test.A, test.B, EquateErrors()); test.WantEqual != gotEqual { 52 t.Fatalf("want %t, got %t", test.WantEqual, gotEqual) 53 } 54 }) 55 } 56 }