-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
49 lines (42 loc) · 1.19 KB
/
errors_test.go
File metadata and controls
49 lines (42 loc) · 1.19 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
package agentmem
import (
"errors"
"fmt"
"testing"
)
func TestErrors(t *testing.T) {
t.Run("ErrNotFound", func(t *testing.T) {
if ErrNotFound.Error() != "entry not found" {
t.Errorf("unexpected message: %s", ErrNotFound.Error())
}
})
t.Run("ErrStoreClosed", func(t *testing.T) {
if ErrStoreClosed.Error() != "store is closed" {
t.Errorf("unexpected message: %s", ErrStoreClosed.Error())
}
})
t.Run("ErrEmptyKey", func(t *testing.T) {
if ErrEmptyKey.Error() != "key must not be empty" {
t.Errorf("unexpected message: %s", ErrEmptyKey.Error())
}
})
t.Run("ErrNilValue", func(t *testing.T) {
if ErrNilValue.Error() != "value must not be nil" {
t.Errorf("unexpected message: %s", ErrNilValue.Error())
}
})
t.Run("errors are wrappable", func(t *testing.T) {
wrapped := fmt.Errorf("op failed: %w", ErrNotFound)
if !errors.Is(wrapped, ErrNotFound) {
t.Error("wrapped error should match ErrNotFound")
}
})
t.Run("errors are distinct", func(t *testing.T) {
if errors.Is(ErrNotFound, ErrStoreClosed) {
t.Error("ErrNotFound should not equal ErrStoreClosed")
}
if errors.Is(ErrEmptyKey, ErrNilValue) {
t.Error("ErrEmptyKey should not equal ErrNilValue")
}
})
}