|
| 1 | +package xmlutil_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "encoding/xml" |
| 6 | + "io/ioutil" |
| 7 | + "net/http" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 11 | + "github.com/aws/aws-sdk-go-v2/private/protocol/xml/xmlutil" |
| 12 | + "github.com/aws/aws-sdk-go-v2/service/ec2" |
| 13 | +) |
| 14 | + |
| 15 | +type DataOutput struct { |
| 16 | + _ struct{} `type:"structure"` |
| 17 | + |
| 18 | + FooEnum string `type:"string" enum:"true"` |
| 19 | + |
| 20 | + ListEnums []string `type:"list"` |
| 21 | +} |
| 22 | + |
| 23 | +func BenchmarkXMLUnmarshal_Simple(b *testing.B) { |
| 24 | + b.ResetTimer() |
| 25 | + for i := 0; i < b.N; i++ { |
| 26 | + req := getXMLResponseSimple() |
| 27 | + xmlutil.UnmarshalXML(req.Data, xml.NewDecoder(req.HTTPResponse.Body), "") |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func BenchmarkXMLUnmarshal_Complex(b *testing.B) { |
| 32 | + b.ResetTimer() |
| 33 | + for i := 0; i < b.N; i++ { |
| 34 | + req := getXMLResponseComplex() |
| 35 | + xmlutil.UnmarshalXML(req.Data, xml.NewDecoder(req.HTTPResponse.Body), "") |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func getXMLResponseSimple() *aws.Request { |
| 40 | + buf := bytes.NewReader([]byte("<OperationNameResponse><FooEnum>foo</FooEnum><ListEnums><member>0</member><member>1</member></ListEnums></OperationNameResponse>")) |
| 41 | + req := aws.Request{Data: &DataOutput{}, HTTPResponse: &http.Response{Body: ioutil.NopCloser(buf)}} |
| 42 | + return &req |
| 43 | +} |
| 44 | + |
| 45 | +func getXMLResponseComplex() *aws.Request { |
| 46 | + buf := bytes.NewReader([]byte(`<?xml version="1.0" encoding="UTF-8"?> |
| 47 | +<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> |
| 48 | + <requestId>7e2ca54c-e2af-4567-bb41-21632d2b839e</requestId> |
| 49 | + <reservationSet> |
| 50 | + <item> |
| 51 | + <reservationId>r-05e953f164a34c484</reservationId> |
| 52 | + <ownerId>183557167593</ownerId> |
| 53 | + <groupSet/> |
| 54 | + <instancesSet> |
| 55 | + <item> |
| 56 | + <instanceId>i-05805668ced0206f0</instanceId> |
| 57 | + <imageId>ami-082b5a644766e0e6f</imageId> |
| 58 | + <instanceState> |
| 59 | + <code>16</code> |
| 60 | + <name>running</name> |
| 61 | + </instanceState> |
| 62 | + <privateDnsName>ip-172-31-30-42.us-west-2.compute.internal</privateDnsName> |
| 63 | + <dnsName>ec2-34-219-17-124.us-west-2.compute.amazonaws.com</dnsName> |
| 64 | + <reason/> |
| 65 | + <keyName>ec2</keyName> |
| 66 | + <amiLaunchIndex>0</amiLaunchIndex> |
| 67 | + <productCodes/> |
| 68 | + <instanceType>t2.micro</instanceType> |
| 69 | + <launchTime>2019-07-01T21:15:47.000Z</launchTime> |
| 70 | + <placement> |
| 71 | + <availabilityZone>us-west-2a</availabilityZone> |
| 72 | + <groupName/> |
| 73 | + <tenancy>default</tenancy> |
| 74 | + </placement> |
| 75 | + <monitoring> |
| 76 | + <state>disabled</state> |
| 77 | + </monitoring> |
| 78 | + <subnetId>subnet-21959558</subnetId> |
| 79 | + <vpcId>vpc-1de55365</vpcId> |
| 80 | + <privateIpAddress>172.31.30.42</privateIpAddress> |
| 81 | + <ipAddress>34.219.17.124</ipAddress> |
| 82 | + <sourceDestCheck>true</sourceDestCheck> |
| 83 | + <groupSet> |
| 84 | + <item> |
| 85 | + <groupId>sg-02d1f51eb2fa52795</groupId> |
| 86 | + <groupName>launch-wizard-2</groupName> |
| 87 | + </item> |
| 88 | + </groupSet> |
| 89 | + <architecture>x86_64</architecture> |
| 90 | + <rootDeviceType>ebs</rootDeviceType> |
| 91 | + <rootDeviceName>/dev/xvda</rootDeviceName> |
| 92 | + <blockDeviceMapping> |
| 93 | + <item> |
| 94 | + <deviceName>/dev/xvda</deviceName> |
| 95 | + <ebs> |
| 96 | + <volumeId>vol-08225e4fc2fde8e73</volumeId> |
| 97 | + <status>attached</status> |
| 98 | + <attachTime>2019-07-01T21:15:48.000Z</attachTime> |
| 99 | + <deleteOnTermination>true</deleteOnTermination> |
| 100 | + </ebs> |
| 101 | + </item> |
| 102 | + </blockDeviceMapping> |
| 103 | + <virtualizationType>hvm</virtualizationType> |
| 104 | + <clientToken/> |
| 105 | + <hypervisor>xen</hypervisor> |
| 106 | + <networkInterfaceSet> |
| 107 | + <item> |
| 108 | + <networkInterfaceId>eni-0ba368b59d3f5230e</networkInterfaceId> |
| 109 | + <subnetId>subnet-21959558</subnetId> |
| 110 | + <vpcId>vpc-1de55365</vpcId> |
| 111 | + <description/> |
| 112 | + <ownerId>183557167593</ownerId> |
| 113 | + <status>in-use</status> |
| 114 | + <macAddress>02:36:86:6e:84:7c</macAddress> |
| 115 | + <privateIpAddress>172.31.30.42</privateIpAddress> |
| 116 | + <privateDnsName>ip-172-31-30-42.us-west-2.compute.internal</privateDnsName> |
| 117 | + <sourceDestCheck>true</sourceDestCheck> |
| 118 | + <groupSet> |
| 119 | + <item> |
| 120 | + <groupId>sg-02d1f51eb2fa52795</groupId> |
| 121 | + <groupName>launch-wizard-2</groupName> |
| 122 | + </item> |
| 123 | + </groupSet> |
| 124 | + <attachment> |
| 125 | + <attachmentId>eni-attach-0d52b5e24dcb77ede</attachmentId> |
| 126 | + <deviceIndex>0</deviceIndex> |
| 127 | + <status>attached</status> |
| 128 | + <attachTime>2019-07-01T21:15:47.000Z</attachTime> |
| 129 | + <deleteOnTermination>true</deleteOnTermination> |
| 130 | + </attachment> |
| 131 | + <association> |
| 132 | + <publicIp>34.219.17.124</publicIp> |
| 133 | + <publicDnsName>ec2-34-219-17-124.us-west-2.compute.amazonaws.com</publicDnsName> |
| 134 | + <ipOwnerId>amazon</ipOwnerId> |
| 135 | + </association> |
| 136 | + <privateIpAddressesSet> |
| 137 | + <item> |
| 138 | + <privateIpAddress>172.31.30.42</privateIpAddress> |
| 139 | + <privateDnsName>ip-172-31-30-42.us-west-2.compute.internal</privateDnsName> |
| 140 | + <primary>true</primary> |
| 141 | + <association> |
| 142 | + <publicIp>34.219.17.124</publicIp> |
| 143 | + <publicDnsName>ec2-34-219-17-124.us-west-2.compute.amazonaws.com</publicDnsName> |
| 144 | + <ipOwnerId>amazon</ipOwnerId> |
| 145 | + </association> |
| 146 | + </item> |
| 147 | + </privateIpAddressesSet> |
| 148 | + <ipv6AddressesSet/> |
| 149 | + <interfaceType>interface</interfaceType> |
| 150 | + </item> |
| 151 | + </networkInterfaceSet> |
| 152 | + <ebsOptimized>false</ebsOptimized> |
| 153 | + <enaSupport>true</enaSupport> |
| 154 | + <cpuOptions> |
| 155 | + <coreCount>1</coreCount> |
| 156 | + <threadsPerCore>1</threadsPerCore> |
| 157 | + </cpuOptions> |
| 158 | + <capacityReservationSpecification> |
| 159 | + <capacityReservationPreference>open</capacityReservationPreference> |
| 160 | + </capacityReservationSpecification> |
| 161 | + <hibernationOptions> |
| 162 | + <configured>false</configured> |
| 163 | + </hibernationOptions> |
| 164 | + </item> |
| 165 | + </instancesSet> |
| 166 | + </item> |
| 167 | + </reservationSet> |
| 168 | +</DescribeInstancesResponse>`)) |
| 169 | + req := aws.Request{Data: &ec2.DescribeInstancesOutput{}, HTTPResponse: &http.Response{Body: ioutil.NopCloser(buf)}} |
| 170 | + return &req |
| 171 | +} |
0 commit comments