navidrome/api/validation_test.go

48 lines
1.2 KiB
Go
Raw Normal View History

2016-02-28 00:42:08 +01:00
package api_test
import (
"encoding/xml"
2016-02-26 00:52:07 +01:00
"github.com/deluan/gosonic/api/responses"
2016-03-02 19:18:39 +01:00
"github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
2016-02-26 00:52:07 +01:00
"testing"
)
func TestCheckParams(t *testing.T) {
2016-02-28 00:42:08 +01:00
tests.Init(t, false)
2016-02-25 00:24:06 +01:00
_, w := Get("/rest/ping.view", "TestCheckParams")
2016-02-25 17:14:16 +01:00
Convey("Subject: CheckParams\n", t, func() {
Convey("Status code should be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The errorCode should be 10", func() {
So(w.Body.String(), ShouldContainSubstring, `error code="10" message=`)
})
Convey("The status should be 'fail'", func() {
v := responses.Subsonic{}
xml.Unmarshal(w.Body.Bytes(), &v)
So(v.Status, ShouldEqual, "fail")
})
})
}
func TestAuthentication(t *testing.T) {
2016-02-25 00:24:06 +01:00
_, w := Get("/rest/ping.view?u=INVALID&p=INVALID&c=test&v=1.0.0", "TestAuthentication")
2016-02-25 17:14:16 +01:00
Convey("Subject: Authentication\n", t, func() {
Convey("Status code should be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The errorCode should be 10", func() {
So(w.Body.String(), ShouldContainSubstring, `error code="40" message=`)
})
Convey("The status should be 'fail'", func() {
v := responses.Subsonic{}
xml.Unmarshal(w.Body.Bytes(), &v)
So(v.Status, ShouldEqual, "fail")
})
})
}