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