|
| 1 | +package provider |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "fmt" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/pact-foundation/pact-go/v2/internal/native" |
| 9 | +) |
| 10 | + |
| 11 | +// TestErrVerificationFailed_IsNativeSentinel guards the re-export: the |
| 12 | +// public provider.ErrVerificationFailed must remain identical to the |
| 13 | +// internal/native sentinel so callers can use errors.Is to discriminate |
| 14 | +// the error returned by Verifier.VerifyProvider. |
| 15 | +func TestErrVerificationFailed_IsNativeSentinel(t *testing.T) { |
| 16 | + if !errors.Is(ErrVerificationFailed, native.ErrVerifierFailed) { |
| 17 | + t.Errorf("ErrVerificationFailed must be the same sentinel as internal/native.ErrVerifierFailed") |
| 18 | + } |
| 19 | + if !errors.Is(ErrVerifierFailedToRun, native.ErrVerifierFailedToRun) { |
| 20 | + t.Errorf("ErrVerifierFailedToRun must be the same sentinel as internal/native.ErrVerifierFailedToRun") |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +// TestErrVerificationFailed_DiscriminatesFromGenericError makes sure the |
| 25 | +// sentinels are not confused with arbitrary error values. |
| 26 | +func TestErrVerificationFailed_DiscriminatesFromGenericError(t *testing.T) { |
| 27 | + generic := fmt.Errorf("something else broke") |
| 28 | + if errors.Is(generic, ErrVerificationFailed) { |
| 29 | + t.Error("generic error should not match ErrVerificationFailed") |
| 30 | + } |
| 31 | + if errors.Is(generic, ErrVerifierFailedToRun) { |
| 32 | + t.Error("generic error should not match ErrVerifierFailedToRun") |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +// TestErrVerificationFailed_DistinctFromEachOther ensures the two sentinels |
| 37 | +// are not interchangeable. |
| 38 | +func TestErrVerificationFailed_DistinctFromEachOther(t *testing.T) { |
| 39 | + if errors.Is(ErrVerificationFailed, ErrVerifierFailedToRun) { |
| 40 | + t.Error("ErrVerificationFailed and ErrVerifierFailedToRun must be distinct") |
| 41 | + } |
| 42 | +} |
0 commit comments