-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon_test.go
More file actions
50 lines (42 loc) · 1.19 KB
/
common_test.go
File metadata and controls
50 lines (42 loc) · 1.19 KB
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
package aspixml
import (
"encoding/xml"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var testFault1 = Fault{
Code: 203,
Msg: "access denied - authentication failed",
}
var testFault1XML = `<Fault>
<FaultCode>203</FaultCode>
<FaultString>access denied - authentication failed</FaultString>
</Fault>`
func TestMarshalFault(t *testing.T) {
b, err := xml.MarshalIndent(&testMessageDelivery1, "", " ")
require.Nil(t, err)
expected := []byte(testMessageDelivery1XML)
assert.Equal(t, expected, b)
}
func TestUnmarshalFault(t *testing.T) {
var f Fault
err := xml.Unmarshal([]byte(testFault1XML), &f)
require.Nil(t, err)
assert.Equal(t, testFault1.Code, f.Code)
assert.Equal(t, testFault1.Msg, f.Msg)
assert.Empty(t, f.Detail)
}
var testFault2XML = `<Fault>
<FaultCode>203</FaultCode>
<FaultString>access denied - authentication failed</FaultString>
<Detail>chan!</Detail>
</Fault>`
func TestUnmarshalFaultWithDetail(t *testing.T) {
var f Fault
err := xml.Unmarshal([]byte(testFault2XML), &f)
require.Nil(t, err)
assert.Equal(t, 203, f.Code)
assert.Equal(t, "access denied - authentication failed", f.Msg)
assert.Equal(t, "chan!", f.Detail)
}