-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
86 lines (72 loc) · 2.03 KB
/
errors_test.go
File metadata and controls
86 lines (72 loc) · 2.03 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
74
75
76
77
78
79
80
81
82
83
84
85
86
package forgeui
import (
"errors"
"testing"
)
func TestComponentError(t *testing.T) {
t.Run("with wrapped error", func(t *testing.T) {
innerErr := errors.New("inner error")
err := &ComponentError{
Component: "Button",
Message: "render failed",
Err: innerErr,
}
expected := "Button: render failed: inner error"
if err.Error() != expected {
t.Errorf("Error() = %v, want %v", err.Error(), expected)
}
if unwrapped := err.Unwrap(); !errors.Is(unwrapped, innerErr) {
t.Errorf("Unwrap() = %v, want %v", unwrapped, innerErr)
}
})
t.Run("without wrapped error", func(t *testing.T) {
err := &ComponentError{
Component: "Card",
Message: "invalid props",
}
expected := "Card: invalid props"
if err.Error() != expected {
t.Errorf("Error() = %v, want %v", err.Error(), expected)
}
if unwrapped := err.Unwrap(); unwrapped != nil {
t.Errorf("Unwrap() should return nil when no wrapped error")
}
})
}
func TestValidationError(t *testing.T) {
err := &ValidationError{
Field: "variant",
Message: "unknown variant type",
}
expected := "validation error on variant: unknown variant type"
if err.Error() != expected {
t.Errorf("Error() = %v, want %v", err.Error(), expected)
}
}
func TestPluginError(t *testing.T) {
t.Run("with wrapped error", func(t *testing.T) {
innerErr := errors.New("init failed")
err := &PluginError{
Plugin: "toast-plugin",
Message: "initialization error",
Err: innerErr,
}
expected := "plugin toast-plugin: initialization error: init failed"
if err.Error() != expected {
t.Errorf("Error() = %v, want %v", err.Error(), expected)
}
if unwrapped := err.Unwrap(); !errors.Is(unwrapped, innerErr) {
t.Errorf("Unwrap() = %v, want %v", unwrapped, innerErr)
}
})
t.Run("without wrapped error", func(t *testing.T) {
err := &PluginError{
Plugin: "chart-plugin",
Message: "not found",
}
expected := "plugin chart-plugin: not found"
if err.Error() != expected {
t.Errorf("Error() = %v, want %v", err.Error(), expected)
}
})
}