-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors_test.go
54 lines (48 loc) · 1.1 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
54
package kouch
import (
"errors"
"testing"
"github.com/go-kivik/couchdb/chttp"
)
func TestExit(t *testing.T) {
tests := []struct {
name string
err error
expected string
status int
}{
{
name: "standard error",
err: errors.New("foo"),
expected: "foo",
status: chttp.ExitUnknownFailure,
},
{
name: "HTTP status error",
err: &httpErr{error: errors.New("foo"), httpStatus: 404, exitStatus: chttp.ExitNotRetrieved},
expected: "The requested URL returned error: 404 foo",
status: chttp.ExitNotRetrieved,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
msg, status := exit(test.err)
if msg != test.expected {
t.Errorf("Unexpected result:\nExpected: %s\n Actual: %s\n", test.expected, msg)
}
if status != test.status {
t.Errorf("Unexpected exit status:\nExpected: %d\n Actual: %d\n", test.status, status)
}
})
}
}
type httpErr struct {
httpStatus, exitStatus int
error
}
func (e *httpErr) StatusCode() int {
return e.httpStatus
}
func (e *httpErr) ExitStatus() int {
return e.exitStatus
}