1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
package smithytesting
import (
"bytes"
"fmt"
"reflect"
"github.com/aws/aws-sdk-go/internal/smithytesting/xml"
)
// XMLEqual asserts two XML documents by sorting the XML and comparing the
// strings It returns an error in case of mismatch or in case of malformed XML
// found while sorting. In case of mismatched XML, the error string will
// contain the diff between the two XML documents.
func XMLEqual(expectBytes, actualBytes []byte) error {
actualString, err := xml.SortXML(bytes.NewBuffer(actualBytes), true)
if err != nil {
return err
}
expectString, err := xml.SortXML(bytes.NewBuffer(expectBytes), true)
if err != nil {
return err
}
if !reflect.DeepEqual(expectString, actualString) {
return fmt.Errorf("unexpected XML mismatch\nexpect: %+v\nactual: %+v",
expectString, actualString)
}
return nil
}
|