Dmitry Polishuk February 2016

Golang: Compare XML structures

I need to write a test to verify server response. Response must contain certain headers and xml body. First, How can I check that the required headers are present in the response. And how can I compare received XML and required XML.

For example. Response must contain header "Serv". And body must me contain xml with object "person"

HTTP/1.1 200 OK
Connection: Keep-Alive
Serv: "any-string"
Content-Length: 0
Content-Type: text/xml; charset=UTF-8
<?xml version="1.0" encoding="utf-8"?>

<person>
  <name>string-value</name>
</person>

How can I check that response contain header "Serv" and contain body xml with element person and name

Answers


Volker February 2016

The headers are accessible through http.Response.Header and the body can be read from http.Request.Body e.g. via ioutil.ReadAll. Then you can compare the expected to the actual data via standard means.

But maybe you should explain more where the actual problem is and what you tried and why it failed.

Post Status

Asked in February 2016
Viewed 3,677 times
Voted 14
Answered 1 times

Search




Leave an answer