-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_test.go
122 lines (118 loc) · 2.36 KB
/
api_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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package sfdcclient
import (
"testing"
)
func TestOAuthErr_Error(t *testing.T) {
type fields struct {
Code string
Description string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Success",
fields: fields{
Code: "invalid_grant",
Description: "Session expired or invalid",
},
want: "OAuth authorization error code: invalid_grant, description: Session expired or invalid",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &OAuthErr{
Code: tt.fields.Code,
Description: tt.fields.Description,
}
if got := e.Error(); got != tt.want {
t.Errorf("OAuthErr.Error() = %+v, want %+v", got, tt.want)
}
})
}
}
func TestAPIErr_Error(t *testing.T) {
type fields struct {
Message string
ErrCode string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Success",
fields: fields{
Message: "Session expired or invalid",
ErrCode: "INVALID_SESSION_ID",
},
want: "error code: INVALID_SESSION_ID, message: Session expired or invalid",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &APIErr{
Message: tt.fields.Message,
ErrCode: tt.fields.ErrCode,
}
if got := e.Error(); got != tt.want {
t.Errorf("APIErr.Error() = %+v, want %+v", got, tt.want)
}
})
}
}
func TestAPIErrs_Error(t *testing.T) {
tests := []struct {
name string
e *APIErrs
want string
}{
{
name: "NilErrs",
e: nil,
want: "",
},
{
name: "EmptyErrsSlice",
e: &APIErrs{},
want: "",
},
{
name: "OneErr",
e: &APIErrs{
APIErr{
ErrCode: "123",
Message: "message",
Fields: []string{"field"},
},
},
want: "error code: 123, message: message, fields: field",
},
{
name: "MultipleErrs",
e: &APIErrs{
APIErr{
ErrCode: "123",
Message: "message",
Fields: []string{"field"},
},
APIErr{
ErrCode: "456",
Message: "otherMessage",
Fields: []string{"otherField"},
},
},
want: "error code: 123, message: message, fields: field|error code: 456, message: otherMessage, fields: otherField",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.e.Error(); got != tt.want {
t.Errorf("APIErrs.Error() = %+v, want %+v", got, tt.want)
}
})
}
}