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
+8 -7
View File
@@ -1,15 +1,15 @@
package api_test
import (
"encoding/xml"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/tests"
. "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
"encoding/json"
)
func TestPing(t *testing.T) {
tests.Init(t, false)
Init(t, false)
_, w := Get(AddParams("/rest/ping.view"), "TestPing")
@@ -21,10 +21,11 @@ func TestPing(t *testing.T) {
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
Convey("The result should be a valid ping response", func() {
v := responses.Subsonic{}
xml.Unmarshal(w.Body.Bytes(), &v)
So(v.Status, ShouldEqual, "ok")
So(v.Version, ShouldEqual, "1.0.0")
v := responses.JsonWrapper{}
err := json.Unmarshal(w.Body.Bytes(), &v)
So(err, ShouldBeNil)
So(v.Subsonic.Status, ShouldEqual, "ok")
So(v.Subsonic.Version, ShouldEqual, "1.0.0")
})
})