mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 19:20:37 +03:00
Better Ping implementation
This commit is contained in:
parent
b9e9d38a9a
commit
ed1a132d8e
@ -4,3 +4,5 @@ runmode = dev
|
||||
autorender = false
|
||||
copyrequestbody = true
|
||||
enableadmin = true
|
||||
|
||||
apiversion = 1.0.0
|
@ -1,14 +1,23 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/astaxie/beego"
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type PingController struct {
|
||||
beego.Controller
|
||||
type PingResponse struct {
|
||||
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response"`
|
||||
Status string `xml:"status,attr"`
|
||||
Version string `xml:"version,attr"`
|
||||
}
|
||||
|
||||
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>")
|
||||
response := &PingResponse{Status:"ok", Version: beego.AppConfig.String("apiversion")}
|
||||
xmlBody, _ := xml.Marshal(response)
|
||||
this.Ctx.Output.Body([]byte(xml.Header + string(xmlBody)))
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/controllers"
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -33,8 +35,11 @@ func TestPing(t *testing.T) {
|
||||
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>")
|
||||
Convey("The Result Should Be A Valid Ping Response", func() {
|
||||
v := controllers.PingResponse{}
|
||||
xml.Unmarshal(w.Body.Bytes(), &v)
|
||||
So(v.Status, ShouldEqual, "ok")
|
||||
So(v.Version, ShouldEqual, "1.0.0")
|
||||
})
|
||||
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user