assert_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package awstesting_test
  2. import (
  3. "encoding/xml"
  4. "testing"
  5. "github.com/aws/aws-sdk-go/awstesting"
  6. )
  7. func TestAssertJSON(t *testing.T) {
  8. cases := []struct {
  9. e, a string
  10. asserts bool
  11. }{
  12. {
  13. e: `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`,
  14. a: `{"RecursiveStruct":{"RecursiveMap":{"bar":{"NoRecurse":"bar"},"foo":{"NoRecurse":"foo"}}}}`,
  15. asserts: true,
  16. },
  17. }
  18. for i, c := range cases {
  19. mockT := &testing.T{}
  20. if awstesting.AssertJSON(mockT, c.e, c.a) != c.asserts {
  21. t.Error("Assert JSON result was not expected.", i)
  22. }
  23. }
  24. }
  25. func TestAssertXML(t *testing.T) {
  26. cases := []struct {
  27. e, a string
  28. asserts bool
  29. container struct {
  30. XMLName xml.Name `xml:"OperationRequest"`
  31. NS string `xml:"xmlns,attr"`
  32. RecursiveStruct struct {
  33. RecursiveMap struct {
  34. Entries []struct {
  35. XMLName xml.Name `xml:"entries"`
  36. Key string `xml:"key"`
  37. Value struct {
  38. XMLName xml.Name `xml:"value"`
  39. NoRecurse string
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }{
  46. {
  47. 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>`,
  48. 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>`,
  49. asserts: true,
  50. },
  51. }
  52. for i, c := range cases {
  53. // mockT := &testing.T{}
  54. if awstesting.AssertXML(t, c.e, c.a, c.container) != c.asserts {
  55. t.Error("Assert XML result was not expected.", i)
  56. }
  57. }
  58. }