-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors_test.go
64 lines (60 loc) · 1.9 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
55
56
57
58
59
60
61
62
63
64
package awql
import "testing"
var reportDefinitionErrorTests = []struct {
xml []byte // in
err string // out
}{
{[]byte(""), ErrNoDsn.Error()},
{[]byte(`
<reportDownloadError>
<ApiError>
<type>ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH</type>
<trigger></trigger>
<fieldPath>selector</fieldPath>
</ApiError>
</reportDownloadError>`), "ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH"},
{[]byte(`
<reportDownloadError>
<ApiError>
<type>ReportDownloadError.ERROR_GETTING_RESPONSE_FROM_BACKEND</type>
<trigger>Unable to read report data</trigger>
<fieldPath></fieldPath>
</ApiError>
</reportDownloadError>`), "ReportDownloadError.ERROR_GETTING_RESPONSE_FROM_BACKEND (Unable to read report data)"},
{[]byte(`
<reportDownloadError>
<ApiError>
<type>QueryError.DATE_COLUMN_REQUIRES_DURING_CLAUSE</type>
<trigger></trigger>
<fieldPath></fieldPath>
</ApiError>
</reportDownloadError>`), "QueryError.DATE_COLUMN_REQUIRES_DURING_CLAUSE"},
{[]byte(`
<reportDownloadError>
<ApiError>
<type>ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT</type>
<trigger></trigger>
<fieldPath>CampaignId</fieldPath>
</ApiError>
</reportDownloadError>`), "ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT on CampaignId"},
{[]byte(`Not a XML`), "EOF"},
}
// TestNewApiError tests the method named NewAPIError.
func TestNewApiError(t *testing.T) {
for _, e := range reportDefinitionErrorTests {
if err := NewAPIError(e.xml); err != nil {
if err.Error() != e.err {
t.Errorf("Expected the error message %v with %s, received %v", e.err, e.xml, err)
}
} else {
t.Errorf("Expected an error with %v", e.xml)
}
}
}
// TestNewQueryError tests the method named NewQueryError.
func TestNewQueryError(t *testing.T) {
err := NewQueryError("hello word")
if err.Error() != "QueryError.HELLO_WORD" {
t.Fatalf("Unexpected error message: %v", err.Error())
}
}