Repository navigation
Expand file tree
/
Copy patherrors_test.go
More file actions
73 lines (66 loc) · 2.04 KB
/
Copy patherrors_test.go
File metadata and controls
73 lines (66 loc) · 2.04 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
71
72
73
package fabriq
import (
"errors"
"fmt"
"testing"
)
func TestSentinelErrors_AreDistinct(t *testing.T) {
sentinels := []error{
ErrNoTenant,
ErrNotFound,
ErrVersionConflict,
ErrProjectionLag,
ErrTenantHookTripped,
ErrStoreNotConfigured,
}
for i, a := range sentinels {
for j, b := range sentinels {
if i != j && errors.Is(a, b) {
t.Errorf("sentinel %v unexpectedly Is %v", a, b)
}
}
}
}
func TestVersionConflictError_IsErrVersionConflict(t *testing.T) {
err := &VersionConflictError{Aggregate: "asset", AggID: "01H", Expected: 3, Actual: 5}
if !errors.Is(err, ErrVersionConflict) {
t.Fatal("VersionConflictError must satisfy errors.Is(err, ErrVersionConflict)")
}
wrapped := fmt.Errorf("exec: %w", err)
if !errors.Is(wrapped, ErrVersionConflict) {
t.Fatal("wrapped VersionConflictError must still match ErrVersionConflict")
}
var vc *VersionConflictError
if !errors.As(wrapped, &vc) {
t.Fatal("errors.As must recover *VersionConflictError")
}
if vc.Expected != 3 || vc.Actual != 5 {
t.Fatalf("recovered conflict carries wrong versions: %+v", vc)
}
}
func TestVersionConflictError_Message(t *testing.T) {
err := &VersionConflictError{Aggregate: "asset", AggID: "01H", Expected: 3, Actual: 5}
want := `fabriq: version conflict on asset/01H: expected 3, actual 5`
if err.Error() != want {
t.Fatalf("Error() = %q, want %q", err.Error(), want)
}
}
func TestNotFoundError_CarriesEntityAndID(t *testing.T) {
err := &NotFoundError{Entity: "site", ID: "01J"}
if !errors.Is(err, ErrNotFound) {
t.Fatal("NotFoundError must satisfy errors.Is(err, ErrNotFound)")
}
want := `fabriq: site "01J" not found`
if err.Error() != want {
t.Fatalf("Error() = %q, want %q", err.Error(), want)
}
}
func TestStructuredError_AliasedAtRoot(t *testing.T) {
e := &Error{Code: CodeNotFound, Message: "x"}
if !errors.Is(e, ErrNotFound) {
t.Fatal("root fabriq.Error aliased type must satisfy errors.Is(err, ErrNotFound)")
}
if CodeSchemaMismatch != "schema_mismatch" {
t.Fatalf("CodeSchemaMismatch alias mismatch: %q", CodeSchemaMismatch)
}
}