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 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
package rundeck
import (
"encoding/xml"
"testing"
)
type marshalTest struct {
Name string
Input interface{}
ExpectedXML string
}
type unmarshalTestFunc func (result interface {}) error
type unmarshalTest struct {
Name string
Input string
Output interface {}
TestFunc unmarshalTestFunc
}
func testMarshalXML(t *testing.T, tests []marshalTest) {
for _, test := range tests {
xmlBytes, err := xml.Marshal(test.Input)
if err != nil {
t.Errorf("Error in Marshall for test %s: %s", test.Name, err.Error())
continue
}
xmlStr := string(xmlBytes)
if xmlStr != test.ExpectedXML {
t.Errorf("Test %s got %s, but wanted %s", test.Name, xmlStr, test.ExpectedXML)
continue
}
}
}
func testUnmarshalXML(t *testing.T, tests []unmarshalTest) {
for _, test := range tests {
xml.Unmarshal([]byte(test.Input), test.Output)
err := test.TestFunc(test.Output)
if err != nil {
t.Errorf("Test %s %s", test.Name, err.Error())
}
}
}
|