-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patherror_test.go
61 lines (57 loc) · 1.25 KB
/
error_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
55
56
57
58
59
60
61
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package diffbot
import (
"testing"
)
func TestError(t *testing.T) {
var e Error
for i := 0; i < len(testErrors); i++ {
if err := e.ParseJson(testErrors[i].str); err != nil {
t.Fatalf("%d: %v", i, err)
}
if a, b := testErrors[i].err.ErrCode, e.ErrCode; a != b {
t.Fatalf("%d: expect = %v, got = %v", i, a, b)
}
if a, b := testErrors[i].err.ErrMessage, e.ErrMessage; a != b {
t.Fatalf("%d: expect = %v, got = %v", i, a, b)
}
if a, b := testErrors[i].str, e.RawString; a != b {
t.Fatalf("%d: expect = %v, got = %v", i, a, b)
}
}
}
var testErrors = []struct {
str string
err Error
}{
{
str: `
{"error":"Not authorized API token.","errorCode":401}
`,
err: Error{
ErrCode: 401,
ErrMessage: "Not authorized API token.",
},
},
{
str: `
{
"errorCode": 404,
"error": "Something went crazy wrong.",
"errorAnalysis": {
"analyzed": "True",
"blame": "human",
"reasonCode": 817221,
"reason": "inherent fallibility"
},
"suggestedImprovement": "Use a robot."
}
`,
err: Error{
ErrCode: 404,
ErrMessage: "Something went crazy wrong.",
},
},
}