forked from blacklightcms/recurly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_unit_amount_test.go
44 lines (38 loc) · 1.33 KB
/
type_unit_amount_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
package recurly
import (
"bytes"
"encoding/xml"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestUnitAmount(t *testing.T) {
type s struct {
Amount UnitAmount `xml:"amount,omitempty"`
}
tests := []struct {
v s
expected string
}{
{v: s{Amount: UnitAmount{USD: 1000}}, expected: "<s><amount><USD>1000</USD></amount></s>"},
{v: s{Amount: UnitAmount{USD: 800, EUR: 650}}, expected: "<s><amount><USD>800</USD><EUR>650</EUR></amount></s>"},
{v: s{Amount: UnitAmount{EUR: 650}}, expected: "<s><amount><EUR>650</EUR></amount></s>"},
{v: s{Amount: UnitAmount{GBP: 3000}}, expected: "<s><amount><GBP>3000</GBP></amount></s>"},
{v: s{Amount: UnitAmount{CAD: 300}}, expected: "<s><amount><CAD>300</CAD></amount></s>"},
{v: s{Amount: UnitAmount{AUD: 400}}, expected: "<s><amount><AUD>400</AUD></amount></s>"},
{v: s{}, expected: "<s></s>"},
{v: s{Amount: UnitAmount{USD: 1}}, expected: "<s><amount><USD>1</USD></amount></s>"},
}
for _, tt := range tests {
var given bytes.Buffer
if err := xml.NewEncoder(&given).Encode(tt.expected); err != nil {
t.Fatalf("unexpected error: %v", err)
}
buf := bytes.NewBufferString(tt.expected)
var dst s
if err := xml.NewDecoder(buf).Decode(&dst); err != nil {
t.Fatalf("unexpected error: %v", err)
} else if diff := cmp.Diff(tt.v, dst); diff != "" {
t.Fatal(diff)
}
}
}