This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
forked from g8rswimmer/go-sfdc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_test.go
72 lines (70 loc) · 1.53 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
62
63
64
65
66
67
68
69
70
71
72
package sfdc
import "testing"
func TestError_UnmarshalJSON(t *testing.T) {
type fields struct {
ErrorCode string
Message string
Fields []string
}
type args struct {
data []byte
}
tests := []struct {
name string
fields fields
args args
want *Error
wantErr bool
}{
{
name: "Success with Status Code",
fields: fields{},
args: args{
data: []byte(`
{
"statusCode" : "MALFORMED_ID",
"message" : "Contact ID: id value of incorrect type: 001xx000003DGb2999",
"fields" : [
"Id"
]
}`),
},
want: &Error{
ErrorCode: "MALFORMED_ID",
Message: "Contact ID: id value of incorrect type: 001xx000003DGb2999",
Fields: []string{"Id"},
},
wantErr: false,
},
{
name: "Success with Error Code",
fields: fields{},
args: args{
data: []byte(`
{
"fields" : [ "Id" ],
"message" : "Account ID: id value of incorrect type: 001900K0001pPuOAAU",
"errorCode" : "MALFORMED_ID"
}`),
},
want: &Error{
ErrorCode: "MALFORMED_ID",
Message: "Account ID: id value of incorrect type: 001900K0001pPuOAAU",
Fields: []string{"Id"},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &Error{
ErrorCode: tt.fields.ErrorCode,
Message: tt.fields.Message,
Fields: tt.fields.Fields,
}
if err := e.UnmarshalJSON(tt.args.data); (err != nil) != tt.wantErr {
t.Errorf("Error.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}