I'm testing XML marshaling with testify and using strings.Contains
to check if lines I expect to be included in the XML are in fact there.
However, I want to diff the actual vs. desired xml.
Currently, my code looks something like:
func (suite *BookSuite) TestXMLMarshal() {
priceXML, priceErr := xml.Marshal(PriceType{Price: 10, Type: "IND"})
suite.Nil(priceErr)
linePresent := strings.Contains(string(priceXML), `<PriceType Price="10" Type="IND"></PriceType>`)
if true != linePresent {
err := errors.New("Expected: \n" + `<PriceType Price="10" Type="IND"></PriceType>` + "\nGot: \n" + bookString)
suite.Error(err, err.Error())
fmt.Println(err)
}
}
There are more lines in the xml file than the single one in the test, so as you can imagine that if statement is going to be gross. Any ideas on cleaning this up that's more scalable?