github.com/aavshr/aws-sdk-go@v1.41.3/private/protocol/xml/xmlutil/sort_test.go (about) 1 package xmlutil 2 3 import ( 4 "encoding/xml" 5 "reflect" 6 "sort" 7 "testing" 8 ) 9 10 func TestXmlAttrSlice(t *testing.T) { 11 tests := []struct { 12 input []xml.Attr 13 expected []xml.Attr 14 }{ 15 { 16 input: []xml.Attr{}, 17 expected: []xml.Attr{}, 18 }, 19 { 20 input: []xml.Attr{ 21 { 22 Name: xml.Name{ 23 Space: "foo", 24 Local: "bar", 25 }, 26 Value: "baz", 27 }, 28 { 29 Name: xml.Name{ 30 Space: "foo", 31 Local: "baz", 32 }, 33 Value: "bar", 34 }, 35 { 36 Name: xml.Name{ 37 Space: "foo", 38 Local: "bar", 39 }, 40 Value: "bar", 41 }, 42 { 43 Name: xml.Name{ 44 Space: "baz", 45 Local: "bar", 46 }, 47 Value: "foo", 48 }, 49 }, 50 expected: []xml.Attr{ 51 { 52 Name: xml.Name{ 53 Space: "baz", 54 Local: "bar", 55 }, 56 Value: "foo", 57 }, 58 { 59 Name: xml.Name{ 60 Space: "foo", 61 Local: "bar", 62 }, 63 Value: "bar", 64 }, 65 { 66 Name: xml.Name{ 67 Space: "foo", 68 Local: "bar", 69 }, 70 Value: "baz", 71 }, 72 { 73 Name: xml.Name{ 74 Space: "foo", 75 Local: "baz", 76 }, 77 Value: "bar", 78 }, 79 }, 80 }, 81 } 82 for i, tt := range tests { 83 sort.Sort(xmlAttrSlice(tt.input)) 84 if e, a := tt.expected, tt.input; !reflect.DeepEqual(e, a) { 85 t.Errorf("case %d expected %v, got %v", i, e, a) 86 } 87 } 88 }