...
1 package awstesting_test
2
3 import (
4 "encoding/xml"
5 "testing"
6
7 "github.com/aws/aws-sdk-go-v2/internal/awstesting"
8 )
9
10 func TestAssertJSON(t *testing.T) {
11 cases := []struct {
12 e, a string
13 asserts bool
14 }{
15 {
16 e: `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`,
17 a: `{"RecursiveStruct":{"RecursiveMap":{"bar":{"NoRecurse":"bar"},"foo":{"NoRecurse":"foo"}}}}`,
18 asserts: true,
19 },
20 }
21
22 for i, c := range cases {
23 mockT := &testing.T{}
24 if awstesting.AssertJSON(mockT, c.e, c.a) != c.asserts {
25 t.Error("Assert JSON result was not expected.", i)
26 }
27 }
28 }
29
30 func TestAssertXML(t *testing.T) {
31 cases := []struct {
32 e, a string
33 asserts bool
34 container struct {
35 XMLName xml.Name `xml:"OperationRequest"`
36 NS string `xml:"xmlns,attr"`
37 RecursiveStruct struct {
38 RecursiveMap struct {
39 Entries []struct {
40 XMLName xml.Name `xml:"entries"`
41 Key string `xml:"key"`
42 Value struct {
43 XMLName xml.Name `xml:"value"`
44 NoRecurse string
45 }
46 }
47 }
48 }
49 }
50 }{
51 {
52 e: `<OperationRequest xmlns="https://foo/"><RecursiveStruct xmlns="https://foo/"><RecursiveMap xmlns="https://foo/"><entry xmlns="https://foo/"><key xmlns="https://foo/">foo</key><value xmlns="https://foo/"><NoRecurse xmlns="https://foo/">foo</NoRecurse></value></entry><entry xmlns="https://foo/"><key xmlns="https://foo/">bar</key><value xmlns="https://foo/"><NoRecurse xmlns="https://foo/">bar</NoRecurse></value></entry></RecursiveMap></RecursiveStruct></OperationRequest>`,
53 a: `<OperationRequest xmlns="https://foo/"><RecursiveStruct xmlns="https://foo/"><RecursiveMap xmlns="https://foo/"><entry xmlns="https://foo/"><key xmlns="https://foo/">bar</key><value xmlns="https://foo/"><NoRecurse xmlns="https://foo/">bar</NoRecurse></value></entry><entry xmlns="https://foo/"><key xmlns="https://foo/">foo</key><value xmlns="https://foo/"><NoRecurse xmlns="https://foo/">foo</NoRecurse></value></entry></RecursiveMap></RecursiveStruct></OperationRequest>`,
54 asserts: true,
55 },
56 }
57
58 for i, c := range cases {
59
60 if awstesting.AssertXML(t, c.e, c.a, c.container) != c.asserts {
61 t.Error("Assert XML result was not expected.", i)
62 }
63 }
64 }
65
66 func TestAssertQuery(t *testing.T) {
67 cases := []struct {
68 e, a string
69 asserts bool
70 }{
71 {
72 e: `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
73 a: `Action=OperationName&Version=2014-01-01&Foo=val2&Bar=val3`,
74 asserts: false,
75 },
76 {
77 e: `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
78 a: `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
79 asserts: true,
80 },
81 }
82
83 for i, c := range cases {
84 mockT := &testing.T{}
85 if awstesting.AssertQuery(mockT, c.e, c.a) != c.asserts {
86 t.Error("Assert Query result was not expected.", i)
87 }
88 }
89 }
90
View as plain text