forked from simpleforce/simpleforce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorHelpers_test.go
56 lines (49 loc) · 1.28 KB
/
errorHelpers_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
package simpleforce
import (
"testing"
)
var expectedError SalesforceError = SalesforceError{
HttpCode: 417,
Message: logPrefix + " Error. http code: 417 Error Message: something went wrong Error Code: SMTH_WRNG",
ErrorCode: "SMTH_WRNG",
ErrorMessage: "something went wrong",
}
func TestSuccessfulJSONParse(t *testing.T) {
response := `[
{
"message": "something went wrong",
"errorCode": "SMTH_WRNG"
}
]`
err := ParseSalesforceError(417, []byte(response))
if err != expectedError {
t.Errorf("failed to parse JSON error, got %s", err)
}
}
func TestSuccessfulXMLParse(t *testing.T) {
response := `
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>SMTH_WRNG</faultcode>
<faultstring xml:lang="en-US">something went wrong</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
`
err := ParseSalesforceError(417, []byte(response))
if err != expectedError {
t.Errorf("failed to parse XML error, got %s", err)
}
}
func TestUnsuccessfulParse(t *testing.T) {
response := "surprise!"
unknownError := SalesforceError{
HttpCode: 417,
Message: "surprise!",
}
err := ParseSalesforceError(417, []byte(response))
if err != unknownError {
t.Errorf("failed to parse unknown error, got %s", err)
}
}