File: assert_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (89 lines) | stat: -rw-r--r-- 2,925 bytes parent folder | download | duplicates (5)
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
package awstesting_test

import (
	"encoding/xml"
	"testing"

	"github.com/aws/aws-sdk-go-v2/internal/awstesting"
)

func TestAssertJSON(t *testing.T) {
	cases := []struct {
		e, a    string
		asserts bool
	}{
		{
			e:       `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`,
			a:       `{"RecursiveStruct":{"RecursiveMap":{"bar":{"NoRecurse":"bar"},"foo":{"NoRecurse":"foo"}}}}`,
			asserts: true,
		},
	}

	for i, c := range cases {
		mockT := &testing.T{}
		if awstesting.AssertJSON(mockT, c.e, c.a) != c.asserts {
			t.Error("Assert JSON result was not expected.", i)
		}
	}
}

func TestAssertXML(t *testing.T) {
	cases := []struct {
		e, a      string
		asserts   bool
		container struct {
			XMLName         xml.Name `xml:"OperationRequest"`
			NS              string   `xml:"xmlns,attr"`
			RecursiveStruct struct {
				RecursiveMap struct {
					Entries []struct {
						XMLName xml.Name `xml:"entries"`
						Key     string   `xml:"key"`
						Value   struct {
							XMLName   xml.Name `xml:"value"`
							NoRecurse string
						}
					}
				}
			}
		}
	}{
		{
			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>`,
			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>`,
			asserts: true,
		},
	}

	for i, c := range cases {
		//		mockT := &testing.T{}
		if awstesting.AssertXML(t, c.e, c.a, c.container) != c.asserts {
			t.Error("Assert XML result was not expected.", i)
		}
	}
}

func TestAssertQuery(t *testing.T) {
	cases := []struct {
		e, a    string
		asserts bool
	}{
		{
			e:       `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
			a:       `Action=OperationName&Version=2014-01-01&Foo=val2&Bar=val3`,
			asserts: false,
		},
		{
			e:       `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
			a:       `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
			asserts: true,
		},
	}

	for i, c := range cases {
		mockT := &testing.T{}
		if awstesting.AssertQuery(mockT, c.e, c.a) != c.asserts {
			t.Error("Assert Query result was not expected.", i)
		}
	}
}