-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_test.go
More file actions
50 lines (43 loc) · 1.12 KB
/
error_test.go
File metadata and controls
50 lines (43 loc) · 1.12 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
package restapi
import (
"errors"
"fmt"
"testing"
)
func TestSentinels_AreDistinct(t *testing.T) {
t.Parallel()
all := []error{
ErrUnknownErrorCode,
ErrCodeAlreadyRegistered,
ErrFallbackErrorCodeRegistration,
ErrInvalidPaginationLimit,
ErrInvalidPaginationOffset,
ErrInvalidPaginationPageSize,
ErrInvalidPaginationPageNumber,
}
seen := make(map[string]struct{}, len(all))
for _, s := range all {
if s == nil {
t.Fatal("sentinel is nil")
}
msg := s.Error()
if _, dup := seen[msg]; dup {
t.Errorf("duplicate sentinel message: %q", msg)
}
seen[msg] = struct{}{}
}
}
func TestSentinels_WrapUnwrapRoundTrip(t *testing.T) {
t.Parallel()
wrapped := fmt.Errorf("%w: %d", ErrCodeAlreadyRegistered, 1234)
if !errors.Is(wrapped, ErrCodeAlreadyRegistered) {
t.Fatal("wrapped error must satisfy errors.Is on its sentinel")
}
}
func TestErrInvalidPaginationOffset_Message(t *testing.T) {
t.Parallel()
// Regression: the message used to be the copy-pasted "invalid limit".
if got := ErrInvalidPaginationOffset.Error(); got != "invalid offset" {
t.Fatalf("got %q; want %q", got, "invalid offset")
}
}