-
Notifications
You must be signed in to change notification settings - Fork 10
/
header_test.go
73 lines (56 loc) · 1.39 KB
/
header_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
package xco
import (
"bytes"
"encoding/xml"
"testing"
)
const headerBody = `
<message
id='asdf'
to='[email protected]'
from='[email protected]/home'>
</message>
`
func TestReadHeader(t *testing.T) {
input := bytes.NewReader([]byte(headerBody))
dec := xml.NewDecoder(input)
var h Header
err := dec.Decode(&h)
if err != nil {
t.Errorf("Unexpected error parsing message header: %s", err)
return
}
if s := h.From.String(); s != "[email protected]/home" {
t.Errorf("Expected from string to be '[email protected]/home', is '%s'", s)
}
if s := h.To.String(); s != "[email protected]" {
t.Errorf("Expected from string to be '[email protected]', is '%s'", s)
}
if h.From.DomainPart != "example.com" {
t.Errorf("domain part equals %s, expected %s", "example.com", h.From.DomainPart)
}
if h.ID != "asdf" {
t.Errorf("Expected ID to be 'asdf', is '%s'", h.ID)
}
}
func TestWriteHeader(t *testing.T) {
b := bytes.NewBuffer([]byte(""))
enc := xml.NewEncoder(b)
var h Header
err := enc.Encode(&h)
if err != nil {
t.Errorf("Unexpected error encoding message header: %s", err)
return
}
//h.From.DomainPart = "example.com"
//h.From.ResourcePart = "home"
h.To = &Address{}
h.To.LocalPart = "goodbye"
h.To.DomainPart = "example.com"
h.To.ResourcePart = "home"
err = enc.Encode(&h)
if err != nil {
t.Errorf("Unexpected error encoding message header: %s", err)
return
}
}