github.com/aavshr/aws-sdk-go@v1.41.3/awstesting/assert_test.go (about)

     1  package awstesting_test
     2  
     3  import (
     4  	"encoding/xml"
     5  	"testing"
     6  
     7  	"github.com/aavshr/aws-sdk-go/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  				XMLName      xml.Name
    39  				RecursiveMap struct {
    40  					XMLName xml.Name
    41  					Entries []struct {
    42  						Key   string `xml:"key"`
    43  						Value struct {
    44  							XMLName   xml.Name `xml:"value"`
    45  							NoRecurse string
    46  						}
    47  					} `xml:"entry"`
    48  				}
    49  			}
    50  		}
    51  	}{
    52  		{
    53  			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>`,
    54  			a:       `<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>`,
    55  			asserts: true,
    56  		},
    57  		{
    58  			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>`,
    59  			a:       `<OperationRequest xmlns="https://foo/"><RecursiveStruct xmlns="https://foo/"><RecursiveMap xmlns="https://foo/"><entry xmlns="https://foo/"><key xmlns="https://foo/">baz</key><value xmlns="https://foo/"><NoRecurse xmlns="https://foo/">baz</NoRecurse></value></entry></RecursiveMap></RecursiveStruct></OperationRequest>`,
    60  			asserts: false,
    61  		},
    62  	}
    63  
    64  	for i, c := range cases {
    65  		mockT := &testing.T{}
    66  		if awstesting.AssertXML(mockT, c.e, c.a) != c.asserts {
    67  			t.Error("Assert XML result was not expected.", i)
    68  		}
    69  	}
    70  }
    71  
    72  func TestAssertQuery(t *testing.T) {
    73  	cases := []struct {
    74  		e, a    string
    75  		asserts bool
    76  	}{
    77  		{
    78  			e:       `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
    79  			a:       `Action=OperationName&Version=2014-01-01&Foo=val2&Bar=val3`,
    80  			asserts: false,
    81  		},
    82  		{
    83  			e:       `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
    84  			a:       `Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2`,
    85  			asserts: true,
    86  		},
    87  	}
    88  
    89  	for i, c := range cases {
    90  		mockT := &testing.T{}
    91  		if awstesting.AssertQuery(mockT, c.e, c.a) != c.asserts {
    92  			t.Error("Assert Query result was not expected.", i)
    93  		}
    94  	}
    95  }