Refactored responses, implemented getLicense
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"runtime"
|
||||
"path/filepath"
|
||||
_ "github.com/deluan/gosonic/routers"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_, file, _, _ := runtime.Caller(1)
|
||||
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, "../.." + string(filepath.Separator))))
|
||||
beego.TestBeegoInit(appPath)
|
||||
}
|
||||
|
||||
// TestGet is a sample to run an endpoint test
|
||||
func TestGetLicense(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/rest/getLicense.view", nil)
|
||||
w := httptest.NewRecorder()
|
||||
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
||||
|
||||
beego.Trace("testing", "TestGetLicense", fmt.Sprintf("Code[%d]\n%s", w.Code, w.Body.String()))
|
||||
|
||||
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"`)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,19 +5,19 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"runtime"
|
||||
"encoding/xml"
|
||||
"path/filepath"
|
||||
_ "github.com/deluan/gosonic/routers"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/controllers"
|
||||
"encoding/xml"
|
||||
"github.com/deluan/gosonic/responses"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_, file, _, _ := runtime.Caller(1)
|
||||
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, "../.." + string(filepath.Separator))))
|
||||
beego.TestBeegoInit(apppath)
|
||||
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, "../.." + string(filepath.Separator))))
|
||||
beego.TestBeegoInit(appPath)
|
||||
}
|
||||
|
||||
// TestGet is a sample to run an endpoint test
|
||||
@@ -26,17 +26,17 @@ func TestPing(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
||||
|
||||
beego.Trace("testing", "TestPing", "Code[%d]\n%s", w.Code, w.Body.String())
|
||||
beego.Trace("testing", "TestPing", fmt.Sprintf("Code[%d]\n%s", w.Code, w.Body.String()))
|
||||
|
||||
Convey("Subject: Ping Endpoint\n", t, func() {
|
||||
Convey("Status Code Should Be 200", func() {
|
||||
Convey("Status code should be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
Convey("The Result Should Not Be Empty", func() {
|
||||
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 := controllers.PingResponse{}
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user