|
| 1 | +package tftypes |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/google/go-cmp/cmp" |
| 8 | +) |
| 9 | + |
| 10 | +func TestAttributePathErrorEqual(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + |
| 13 | + testCases := map[string]struct { |
| 14 | + ape AttributePathError |
| 15 | + other AttributePathError |
| 16 | + expected bool |
| 17 | + }{ |
| 18 | + "equal": { |
| 19 | + ape: AttributePathError{ |
| 20 | + Path: NewAttributePath().WithAttributeName("test"), |
| 21 | + err: errors.New("test error"), |
| 22 | + }, |
| 23 | + other: AttributePathError{ |
| 24 | + Path: NewAttributePath().WithAttributeName("test"), |
| 25 | + err: errors.New("test error"), |
| 26 | + }, |
| 27 | + expected: true, |
| 28 | + }, |
| 29 | + "err-different": { |
| 30 | + ape: AttributePathError{ |
| 31 | + Path: NewAttributePath().WithAttributeName("test"), |
| 32 | + err: errors.New("test error"), |
| 33 | + }, |
| 34 | + other: AttributePathError{ |
| 35 | + Path: NewAttributePath().WithAttributeName("test"), |
| 36 | + err: errors.New("different error"), |
| 37 | + }, |
| 38 | + expected: false, |
| 39 | + }, |
| 40 | + "err-nil": { |
| 41 | + ape: AttributePathError{ |
| 42 | + Path: NewAttributePath().WithAttributeName("test"), |
| 43 | + err: nil, |
| 44 | + }, |
| 45 | + other: AttributePathError{ |
| 46 | + Path: NewAttributePath().WithAttributeName("test"), |
| 47 | + err: nil, |
| 48 | + }, |
| 49 | + expected: true, |
| 50 | + }, |
| 51 | + "err-nil-ape": { |
| 52 | + ape: AttributePathError{ |
| 53 | + Path: NewAttributePath().WithAttributeName("test"), |
| 54 | + err: nil, |
| 55 | + }, |
| 56 | + other: AttributePathError{ |
| 57 | + Path: NewAttributePath().WithAttributeName("test"), |
| 58 | + err: errors.New("test error"), |
| 59 | + }, |
| 60 | + expected: false, |
| 61 | + }, |
| 62 | + "err-nil-other": { |
| 63 | + ape: AttributePathError{ |
| 64 | + Path: NewAttributePath().WithAttributeName("test"), |
| 65 | + err: errors.New("test error"), |
| 66 | + }, |
| 67 | + other: AttributePathError{ |
| 68 | + Path: NewAttributePath().WithAttributeName("test"), |
| 69 | + err: nil, |
| 70 | + }, |
| 71 | + expected: false, |
| 72 | + }, |
| 73 | + "path-different": { |
| 74 | + ape: AttributePathError{ |
| 75 | + Path: NewAttributePath().WithAttributeName("test"), |
| 76 | + err: errors.New("test error"), |
| 77 | + }, |
| 78 | + other: AttributePathError{ |
| 79 | + Path: NewAttributePath().WithAttributeName("different"), |
| 80 | + err: errors.New("test error"), |
| 81 | + }, |
| 82 | + expected: false, |
| 83 | + }, |
| 84 | + } |
| 85 | + |
| 86 | + for name, testCase := range testCases { |
| 87 | + name, testCase := name, testCase |
| 88 | + t.Run(name, func(t *testing.T) { |
| 89 | + t.Parallel() |
| 90 | + |
| 91 | + got := testCase.ape.Equal(testCase.other) |
| 92 | + |
| 93 | + if diff := cmp.Diff(testCase.expected, got); diff != "" { |
| 94 | + t.Errorf("Unexpected results (-wanted +got): %s", diff) |
| 95 | + } |
| 96 | + }) |
| 97 | + } |
| 98 | +} |
0 commit comments