-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
71 lines (63 loc) · 1.24 KB
/
main_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
package main
import (
"bytes"
"encoding/json"
"testing"
xj "github.com/basgys/goxml2json"
"github.com/stretchr/testify/assert"
)
type Customers struct {
customer []Customer
}
type Customer struct {
ID int
name string
order []Order
transaction float64
}
type Order struct {
ID int
product int64
name string
}
func TestConvStream(t *testing.T) {
assert := assert.New(t)
var customers []Customers
r := []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer id="1">
<name>blah</name>
<order id="666eefff">
<product id="34223">
<name>vin</name>
</product>
</order>
<transaction>19.95</transaction>
</customer>
<customer id="2">
<name>meh</name>
<order id="edf7f1ad">
<product id="2222">
<name>øl</name>
</product>
</order>
<transaction>6.50</transaction>
</customer>
<customer id="4">
<name>yep</name>
<order id="dd27f6f8">
<product id="11111">
<name>log</name>
</product>
</order>
<transaction>61.08</transaction>
</customer>
</customers>`)
c, err := xj.Convert(bytes.NewReader(r), xj.WithAttrPrefix(""))
if err != nil {
t.Error("Failed to convert")
}
json.Unmarshal(c.Bytes(), &customers)
assert.Nil(customers)
}