Small fixes to response marshaling, introduced tests for response formats

This commit is contained in:
Deluan
2016-03-02 17:23:26 -05:00
parent b9fb5eb7ca
commit dde130e84e
10 changed files with 154 additions and 41 deletions
+33
View File
@@ -0,0 +1,33 @@
package tests
import (
. "github.com/smartystreets/goconvey/convey"
"encoding/json"
"encoding/xml"
"fmt"
)
func ShouldMatchXML(actual interface{}, expected ...interface{}) string {
xml, err := xml.Marshal(actual)
if err != nil {
return fmt.Sprintf("Malformed XML: %v", err)
}
return ShouldEqual(string(xml), expected[0].(string))
}
func ShouldMatchJSON(actual interface{}, expected ...interface{}) string {
json, err := json.Marshal(actual)
if err != nil {
return fmt.Sprintf("Malformed JSON: %v", err)
}
s := UnindentJSON(json)
return ShouldEqual(s, expected[0].(string))
}
func UnindentJSON(j []byte) string {
var m = make(map[string]interface{})
json.Unmarshal(j, &m)
s, _ := json.Marshal(m)
return string(s)
}