-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
53 lines (43 loc) · 1.34 KB
/
errors_test.go
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
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
type testCases struct {
ID int
Code int
Res exitError
}
var cases = []testCases{
{1, -1, exitError{errUnknown, 1, "unknown error."}},
{2, 0, exitError{errOK, 0, "Exited, bye."}},
{3, 1, exitError{errNoParams, 1, "Unspecified params: "}},
{4, 2, exitError{errParh, 1, "error in path: "}},
{5, 3, exitError{errFileTypes, 1, "error in file types: "}},
{6, 4, exitError{errScript, 1, "error in script: "}},
{7, 5, exitError{errStorage, 1, "error building storage"}},
{8, 100, exitError{errUnknown, 1, "unknown error."}},
{9, -1, exitError{errUnknown, 1, "unknown error."}},
{10, -2, exitError{errContinue, 0, ""}},
}
func TestExitError(t *testing.T) {
for _, c := range cases {
if r := cmp.Equal(exitErrorFor(c.Code), c.Res); !r {
t.Errorf("case %d diffs: \ngot: %v\nshould be: %v", c.ID, exitErrorFor(c.Code), c.Res)
}
}
}
func TestExitErrorCode(t *testing.T) {
for _, c := range cases {
if exitErrorCode(c.Code) != c.Res.Exit {
t.Errorf("case %d failed, got [%d] should be [%d] ", c.ID, exitErrors[c.Code].Exit, c.Res.Exit)
}
}
}
func TestExitErrorInfo(t *testing.T) {
for _, c := range cases {
if exitErrorInfo(c.Code) != c.Res.Description {
t.Errorf("case %d failed, got [%s] should be [%s]", c.ID, exitErrors[c.Code].Description, c.Res.Description)
}
}
}