-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
103 lines (95 loc) · 1.94 KB
/
errors_test.go
File metadata and controls
103 lines (95 loc) · 1.94 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cli
import (
"testing"
)
// TestErrorTypes tests custom error type creation
func TestErrorTypes(t *testing.T) {
cmd := Root("test")
t.Run("CommandNotFoundError", func(t *testing.T) {
err := &CommandNotFoundError{
Name: "nonexistent",
Cmd: cmd,
}
msg := err.Error()
if msg == "" {
t.Error("error message should not be empty")
}
if err.Cmd != cmd {
t.Error("command reference should be preserved")
}
})
t.Run("ArgumentError", func(t *testing.T) {
err := &ArgumentError{
Arg: "count",
Msg: "invalid value",
Cmd: cmd,
}
msg := err.Error()
if msg == "" {
t.Error("error message should not be empty")
}
if err.Cmd != cmd {
t.Error("command reference should be preserved")
}
})
t.Run("FlagError", func(t *testing.T) {
err := &FlagError{
Flag: "verbose",
Msg: "invalid flag",
Cmd: cmd,
}
msg := err.Error()
if msg == "" {
t.Error("error message should not be empty")
}
if err.Cmd != cmd {
t.Error("command reference should be preserved")
}
})
}
// TestErrorMessages tests error message formatting
func TestErrorMessages(t *testing.T) {
cmd := Root("myapp")
tests := []struct {
name string
err error
contains string
}{
{
name: "CommandNotFoundError message",
err: &CommandNotFoundError{
Name: "deploy",
Cmd: cmd,
},
contains: "deploy",
},
{
name: "ArgumentError message",
err: &ArgumentError{
Arg: "count",
Msg: "must be positive",
Cmd: cmd,
},
contains: "count",
},
{
name: "FlagError message",
err: &FlagError{
Flag: "timeout",
Msg: "invalid duration",
Cmd: cmd,
},
contains: "timeout",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msg := tt.err.Error()
if msg == "" {
t.Error("error message should not be empty")
}
// Error messages should contain relevant context
// (exact format not specified, just checking it's not empty)
})
}
}