forked from takbok/shared-contacts-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SharedContactsDemo_test.go
117 lines (105 loc) · 3.16 KB
/
SharedContactsDemo_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2016 Takbok, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package demo
import (
"encoding/xml"
"testing"
)
const testFeed = `<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:gContact='http://schemas.google.com/contact/2008'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:batch='http://schemas.google.com/gdata/batch'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2008#contact' />
<entry>
<batch:id>1</batch:id>
<batch:operation type='insert' />
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2008#contact'/>
<gd:name>
<gd:givenName>Contact</gd:givenName>
<gd:familyName>One</gd:familyName>
</gd:name>
<gd:email rel='http://schemas.google.com/g/2005#home'
address='[email protected]' primary='true'/>
</entry>
<entry>
<batch:id>2</batch:id>
<batch:operation type='insert' />
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2008#contact'/>
<gd:name>
<gd:givenName>Contact</gd:givenName>
<gd:familyName>Two</gd:familyName>
</gd:name>
<gd:email rel='http://schemas.google.com/g/2005#home'
address='[email protected]'
primary='true'/>
</entry>
</feed>`
func TestFeed(t *testing.T) {
var feed Feed
if err := xml.Unmarshal([]byte(testFeed), &feed); err != nil {
t.Errorf("unmarshal feed: %v", err)
return
}
if n := len(feed.Entry); n != 2 {
t.Errorf("len(feed.Entry) != 2")
return
}
e1 := &feed.Entry[0]
e2 := &feed.Entry[1]
if s := e1.Name.GivenName; s != "Contact" {
t.Errorf("e1.Name.GivenName != Contact (%v)", s)
return
}
if s := e1.Name.FamilyName; s != "One" {
t.Errorf("e1.Name.FamilyName != One (%v)", s)
return
}
if s := e2.Name.GivenName; s != "Contact" {
t.Errorf("e2.Name.GivenName != Contact (%v)", s)
return
}
if s := e2.Name.FamilyName; s != "Two" {
t.Errorf("e2.Name.FamilyName != Two (%v)", s)
return
}
if n := len(e1.Email); n != 1 {
t.Errorf("len(e1.Email) != 1 (%v)", n)
return
}
if n := len(e2.Email); n != 1 {
t.Errorf("len(e2.Email) != 1 (%v)", n)
return
}
em1 := e1.Email[0]
em2 := e2.Email[0]
if s := em1.Address; s != "[email protected]" {
t.Errorf("em1.Address != [email protected] (%v)", s)
return
}
if s := em2.Address; s != "[email protected]" {
t.Errorf("em2.Address != [email protected] (%v)", s)
return
}
if b := em1.Primary; !b {
t.Errorf("!em1.Primary (%v)", b)
return
}
if b := em2.Primary; !b {
t.Errorf("!em2.Primary (%v)", b)
return
}
}