-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors_test.go
More file actions
70 lines (61 loc) · 1.89 KB
/
Copy patherrors_test.go
File metadata and controls
70 lines (61 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package idemkit
import (
"errors"
"fmt"
"strings"
"testing"
)
func TestErrBodyMismatch_IdentityUnderIs(t *testing.T) {
if !errors.Is(ErrBodyMismatch, ErrBodyMismatch) {
t.Fatal("sentinel does not match itself via errors.Is")
}
}
func TestErrBodyMismatch_MatchesWhenWrapped(t *testing.T) {
wrapped := fmt.Errorf("store layer: %w", ErrBodyMismatch)
if !errors.Is(wrapped, ErrBodyMismatch) {
t.Fatal("wrapped error does not match ErrBodyMismatch via errors.Is")
}
}
func TestErrBodyMismatch_DoesNotMatchUnrelated(t *testing.T) {
other := errors.New("different error")
if errors.Is(other, ErrBodyMismatch) {
t.Fatal("unrelated error spuriously matches ErrBodyMismatch")
}
}
func TestErrBodyMismatch_MessageIsInformative(t *testing.T) {
msg := ErrBodyMismatch.Error()
if msg == "" {
t.Fatal("error message is empty")
}
if !strings.Contains(msg, "idemkit") {
t.Fatalf("error message %q does not identify the package", msg)
}
}
func TestErrTokenMismatch_IdentityUnderIs(t *testing.T) {
if !errors.Is(ErrTokenMismatch, ErrTokenMismatch) {
t.Fatal("sentinel does not match itself via errors.Is")
}
}
func TestErrTokenMismatch_MatchesWhenWrapped(t *testing.T) {
wrapped := fmt.Errorf("store layer: %w", ErrTokenMismatch)
if !errors.Is(wrapped, ErrTokenMismatch) {
t.Fatal("wrapped error does not match ErrTokenMismatch via errors.Is")
}
}
func TestErrTokenMismatch_DistinctFromBodyMismatch(t *testing.T) {
if errors.Is(ErrTokenMismatch, ErrBodyMismatch) {
t.Fatal("ErrTokenMismatch should not match ErrBodyMismatch")
}
if errors.Is(ErrBodyMismatch, ErrTokenMismatch) {
t.Fatal("ErrBodyMismatch should not match ErrTokenMismatch")
}
}
func TestErrTokenMismatch_MessageIsInformative(t *testing.T) {
msg := ErrTokenMismatch.Error()
if msg == "" {
t.Fatal("error message is empty")
}
if !strings.Contains(msg, "idemkit") {
t.Fatalf("error message %q does not identify the package", msg)
}
}