🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
First endpoint: Ping
Deluanb9e9d38a9aea
diff --git a/conf/app.conf b/conf/app.confindex d3cbf4683..955df9ef1 100644--- a/conf/app.conf+++ b/conf/app.conf@@ -3,4 +3,4 @@ httpport = 8080runmode = devautorender = falsecopyrequestbody = true-EnableDocs = false+enableadmin = truediff --git a/controllers/ping.go b/controllers/ping.gonew file mode 100644index 000000000..69b8c2ac4--- /dev/null+++ b/controllers/ping.go@@ -0,0 +1,15 @@+package controllers++import "github.com/astaxie/beego"++type PingController struct {+ beego.Controller+}++// @router /rest/ping.view [get]+func (this *PingController) Get() {+ this.Ctx.WriteString("<subsonic-response xmlns=\"http://subsonic.org/restapi\" status=\"ok\" version=\"1.0.0\"></subsonic-response>")+}+++diff --git a/routers/router.go b/routers/router.goindex 53b07f952..f2997e954 100644--- a/routers/router.go+++ b/routers/router.go@@ -14,17 +14,5 @@ import ()func init() {- ns := beego.NewNamespace("/v1",- beego.NSNamespace("/object",- beego.NSInclude(- &controllers.ObjectController{},- ),- ),- beego.NSNamespace("/user",- beego.NSInclude(- &controllers.UserController{},- ),- ),- )- beego.AddNamespace(ns)+ beego.Include(&controllers.PingController{})}diff --git a/tests/controllers/ping_test.go b/tests/controllers/ping_test.gonew file mode 100644index 000000000..b04b16fc2--- /dev/null+++ b/tests/controllers/ping_test.go@@ -0,0 +1,42 @@+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"+)++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 TestPing(t *testing.T) {+ r, _ := http.NewRequest("GET", "/rest/ping.view", nil)+ w := httptest.NewRecorder()+ beego.BeeApp.Handlers.ServeHTTP(w, r)++ beego.Trace("testing", "TestPing", "Code[%d]\n%s", w.Code, w.Body.String())++ 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 Pong", func() {+ So(w.Body.String(), ShouldEqual, "<subsonic-response xmlns=\"http://subsonic.org/restapi\" status=\"ok\" version=\"1.0.0\"></subsonic-response>")+ })++ })+}+diff --git a/tests/default_test.go b/tests/default_test.goindex 8362ad795..de2075bfc 100644--- a/tests/default_test.go+++ b/tests/default_test.go@@ -19,7 +19,7 @@ func init() {}// TestGet is a sample to run an endpoint test-func TestGet(t *testing.T) {+func xTestGet(t *testing.T) {r, _ := http.NewRequest("GET", "/v1/object", nil)w := httptest.NewRecorder()beego.BeeApp.Handlers.ServeHTTP(w, r)