(t *testing.T)
| 237 | } |
| 238 | |
| 239 | func Test_FetchXMLRootElement(t *testing.T) { |
| 240 | cases := map[string]struct { |
| 241 | responseBody io.Reader |
| 242 | expectedStartElement xml.StartElement |
| 243 | expectedError string |
| 244 | }{ |
| 245 | "simple success case": { |
| 246 | responseBody: bytes.NewReader([]byte(`<Response><Struct>abc</Struct></Response>`)), |
| 247 | expectedStartElement: xml.StartElement{ |
| 248 | Name: xml.Name{ |
| 249 | Local: "Response", |
| 250 | }, |
| 251 | Attr: []xml.Attr{}, |
| 252 | }, |
| 253 | }, |
| 254 | "empty body": { |
| 255 | responseBody: bytes.NewReader([]byte(``)), |
| 256 | expectedError: "EOF", |
| 257 | }, |
| 258 | "with indentation": { |
| 259 | responseBody: bytes.NewReader([]byte(` <ErrorResponse> |
| 260 | <Error> |
| 261 | <Type>Sender</Type> |
| 262 | <Code>InvalidGreeting</Code> |
| 263 | <Message>Hi</Message> |
| 264 | <AnotherSetting>setting</AnotherSetting> |
| 265 | </Error> |
| 266 | <RequestId>foo-id</RequestId> |
| 267 | </ErrorResponse>`)), |
| 268 | expectedStartElement: xml.StartElement{ |
| 269 | Name: xml.Name{ |
| 270 | Local: "ErrorResponse", |
| 271 | }, |
| 272 | Attr: []xml.Attr{}, |
| 273 | }, |
| 274 | }, |
| 275 | "with preamble": { |
| 276 | responseBody: bytes.NewReader([]byte(`<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?> |
| 277 | <ErrorResponse> |
| 278 | <Error> |
| 279 | <Type>Sender</Type> |
| 280 | <Code>InvalidGreeting</Code> |
| 281 | <Message>Hi</Message> |
| 282 | <AnotherSetting>setting</AnotherSetting> |
| 283 | </Error> |
| 284 | <RequestId>foo-id</RequestId> |
| 285 | </ErrorResponse>`)), |
| 286 | expectedStartElement: xml.StartElement{ |
| 287 | Name: xml.Name{ |
| 288 | Local: "ErrorResponse", |
| 289 | }, |
| 290 | Attr: []xml.Attr{}, |
| 291 | }, |
| 292 | }, |
| 293 | "with comments": { |
| 294 | responseBody: bytes.NewReader([]byte(`<!--Sample comment for testing--> |
| 295 | <?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?> |
| 296 | <ErrorResponse> |
nothing calls this directly
no test coverage detected