-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_response_test.go
80 lines (65 loc) · 2.06 KB
/
error_response_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
package eurlex
import (
"io/ioutil"
"strings"
"testing"
)
func TestInvalidErrorResponse(t *testing.T) {
er, err := NewErrorResponseFromXML("")
if er != nil {
t.Errorf("Returned envelope where it should be nil")
}
if err == nil {
t.Errorf("Should have returned an error message")
}
if !strings.Contains(err.Error(), errorFailedToCreateResponse) {
t.Errorf("Returned wrong error message")
}
}
func TestAuthenticationErrorResponseFromXML(t *testing.T) {
inputFile := "./fixtures/error_response_authentication.xml"
xmlBytes, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Errorf("Failed to load fixtures %s: %s", inputFile, err)
}
er, err := NewErrorResponseFromXML(string(xmlBytes))
if err != nil {
t.Errorf("Failed to unmarshal error response from XML: %s", err)
t.FailNow()
}
if er.Code != "env:Sender" {
t.Errorf("Invalid field Code, got %s, want %s", er.Code, "env:Sender")
}
if er.Reason != "Failed to assert identity with UsernameToken." {
t.Errorf("Invalid field Reason, got %s, want: %s", er.Reason, "Failed to assert identity with UsernameToken.")
}
// @TODO Add more tests for different error responses (i.e. wrong query)
}
func TestErrorResponseEmptyBody(t *testing.T) {
inputFile := "./fixtures/error_response_empty_body.xml"
xmlBytes, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Errorf("Failed to load fixtures %s: %s", inputFile, err)
}
er, err := NewErrorResponseFromXML(string(xmlBytes))
if err == nil {
t.Errorf("Expected error message due to missing body")
}
if er != nil {
t.Errorf("Expected ErrorResponse to be nil, due to missing body element")
}
}
func TestErrorResponseEmptyFault(t *testing.T) {
inputFile := "./fixtures/error_response_empty_fault.xml"
xmlBytes, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Errorf("Failed to load fixtures %s: %s", inputFile, err)
}
er, err := NewErrorResponseFromXML(string(xmlBytes))
if err == nil {
t.Errorf("Expected error message due to missing body")
}
if er != nil {
t.Errorf("Expected ErrorResponse to be nil, due to missing fault element")
}
}