quintodrome/tests/controllers/ping_test.go

48 lines
1.2 KiB
Go
Raw Normal View History

2016-02-23 20:07:57 -09:00
package test
import (
"net/http"
"net/http/httptest"
"testing"
"runtime"
"encoding/xml"
2016-02-23 20:07:57 -09:00
"path/filepath"
_ "github.com/deluan/gosonic/routers"
"github.com/astaxie/beego"
. "github.com/smartystreets/goconvey/convey"
"fmt"
"github.com/deluan/gosonic/controllers/responses"
"github.com/deluan/gosonic/tests"
2016-02-23 20:07:57 -09:00
)
func init() {
_, file, _, _ := runtime.Caller(1)
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, "../.." + string(filepath.Separator))))
beego.TestBeegoInit(appPath)
2016-02-23 20:07:57 -09:00
}
func TestPing(t *testing.T) {
r, _ := http.NewRequest("GET", test.AddParams("/rest/ping.view"), nil)
2016-02-23 20:07:57 -09:00
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", "TestPing", fmt.Sprintf("\nUrl: %s\n\nCode[%d]\n%s", r.URL, w.Code, w.Body.String()))
2016-02-23 20:07:57 -09:00
Convey("Subject: Ping Endpoint\n", t, func() {
Convey("Status code should be 200", func() {
2016-02-23 20:07:57 -09:00
So(w.Code, ShouldEqual, 200)
})
Convey("The result should not be empty", func() {
2016-02-23 20:07:57 -09:00
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
Convey("The result should be a valid ping response", func() {
v := responses.Subsonic{}
2016-02-23 20:29:27 -09:00
xml.Unmarshal(w.Body.Bytes(), &v)
So(v.Status, ShouldEqual, "ok")
So(v.Version, ShouldEqual, "1.0.0")
2016-02-23 20:07:57 -09:00
})
})
}