-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexit_test.go
More file actions
60 lines (57 loc) · 1.03 KB
/
exit_test.go
File metadata and controls
60 lines (57 loc) · 1.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
package exit
import (
"fmt"
"os/exec"
"testing"
)
func TestFromError(t *testing.T) {
// Test cases for the FromError function
tests := []struct {
name string
err error
want int
}{
{
name: "nil",
err: nil,
want: 0,
},
{
name: "exit error",
err: ErrInternalError,
want: 100,
},
{
name: "error",
err: fmt.Errorf("wrapped error"),
want: 1,
},
{
name: "wrapped error",
err: Wrap(fmt.Errorf("wrapped error"), UsageError),
want: 80,
},
{
name: "error wrapped more than once",
err: Wrap(Wrap(fmt.Errorf("wrapped error"), UsageError), Unavailable),
want: 101,
},
{
name: "*exec.ExitError",
err: exec.Command("sh", "-c", "exit 3").Run(),
want: 3,
},
{
name: "wrapped *exec.ExitError",
err: Wrap(exec.Command("exit 3").Run(), NotOK),
want: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FromError(tt.err); got != tt.want {
t.Errorf("FromError(%+v): got %v, want %v", tt.err, got, tt.want)
}
})
}
}