Controller tests are in fact API tests
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
_ "github.com/deluan/gosonic/routers"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
"encoding/xml"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestGetLicense(t *testing.T) {
|
||||
_, w := Get(AddParams("/rest/getLicense.view"), "TestGetLicense")
|
||||
|
||||
Convey("Subject: GetLicense Endpoint\n", t, func() {
|
||||
Convey("Status code should be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
Convey("The license should always be valid", func() {
|
||||
v := new(string)
|
||||
err := xml.Unmarshal(w.Body.Bytes(), &v)
|
||||
So(err, ShouldBeNil)
|
||||
So(w.Body.String(), ShouldContainSubstring, `license valid="true"`)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
_ "github.com/deluan/gosonic/routers"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
func TestGetMusicFolders(t *testing.T) {
|
||||
_, w := Get(AddParams("/rest/getMusicFolders.view"), "TestGetMusicFolders")
|
||||
|
||||
Convey("Subject: GetMusicFolders Endpoint\n", t, func() {
|
||||
Convey("Status code should be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
Convey("The response should include the default folder", func() {
|
||||
v := new(string)
|
||||
err := xml.Unmarshal(w.Body.Bytes(), &v)
|
||||
So(err, ShouldBeNil)
|
||||
So(w.Body.String(), ShouldContainSubstring, `musicFolder id="0" name="iTunes Library"`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"encoding/xml"
|
||||
_ "github.com/deluan/gosonic/routers"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/controllers/responses"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
_, w := Get(AddParams("/rest/ping.view"), "TestPing")
|
||||
|
||||
Convey("Subject: Ping Endpoint\n", t, func() {
|
||||
Convey("Status code should be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
Convey("The result should not be empty", func() {
|
||||
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")
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"encoding/xml"
|
||||
_ "github.com/deluan/gosonic/routers"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/controllers/responses"
|
||||
)
|
||||
|
||||
func TestCheckParams(t *testing.T) {
|
||||
_, w := Get("/rest/ping.view", "TestCheckParams")
|
||||
|
||||
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) {
|
||||
_, w := Get("/rest/ping.view?u=INVALID&p=INVALID&c=test&v=1.0.0", "TestAuthentication")
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user