-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_test.go
72 lines (65 loc) · 2.52 KB
/
node_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
package protobufquery
import (
"encoding/xml"
"testing"
"github.com/stretchr/testify/require"
"github.com/srebhan/protobufquery/testcases/addressbook"
)
var addressbookSample = &addressbook.AddressBook{
People: []*addressbook.Person{
{
Name: "John Doe",
Id: 101,
Email: "[email protected]",
Age: 42,
},
{
Name: "Jane Doe",
Id: 102,
Age: 40,
},
{
Name: "Jack Doe",
Id: 201,
Email: "[email protected]",
Age: 12,
Phones: []*addressbook.Person_PhoneNumber{
{Number: "555-555-5555", Type: addressbook.Person_WORK},
},
},
{
Name: "Jack Buck",
Id: 301,
Email: "[email protected]",
Age: 19,
Phones: []*addressbook.Person_PhoneNumber{
{Number: "555-555-0000", Type: addressbook.Person_HOME},
{Number: "555-555-0001", Type: addressbook.Person_MOBILE},
{Number: "555-555-0002", Type: addressbook.Person_WORK},
},
},
{
Name: "Janet Doe",
Id: 1001,
Email: "[email protected]",
Age: 16,
Phones: []*addressbook.Person_PhoneNumber{
{Number: "555-777-0000"},
{Number: "555-777-0001", Type: addressbook.Person_HOME},
},
},
},
Tags: []string{"home", "private", "friends"},
}
func TestParseAddressBookXML(t *testing.T) {
msg := addressbookSample.ProtoReflect()
doc, err := Parse(msg)
require.NoError(t, err)
require.Len(t, doc.ChildNodes(), 6)
expectedXML := `<?xml version="1.0"?><people><name>John Doe</name><id>101</id><email>[email protected]</email><age>42</age></people><people><name>Jane Doe</name><id>102</id><age>40</age></people><people><name>Jack Doe</name><id>201</id><email>[email protected]</email><age>12</age><phones><number>555-555-5555</number><type>2</type></phones></people><people><name>Jack Buck</name><id>301</id><email>[email protected]</email><age>19</age><phones><number>555-555-0000</number><type>1</type></phones><phones><number>555-555-0001</number></phones><phones><number>555-555-0002</number><type>2</type></phones></people><people><name>Janet Doe</name><id>1001</id><email>[email protected]</email><age>16</age><phones><number>555-777-0000</number></phones><phones><number>555-777-0001</number><type>1</type></phones></people><tags><element>home</element><element>private</element><element>friends</element></tags>`
var actual, expected addressbook.AddressBook
require.NoError(t, xml.Unmarshal([]byte(expectedXML), &expected))
require.NoError(t, xml.Unmarshal([]byte(doc.OutputXML()), &actual))
//nolint:govet // Copies lock but that's the simplest way to test
require.EqualValues(t, expected, actual)
}