First endpoint: Ping

This commit is contained in:
Deluan 2016-02-24 00:07:57 -05:00
parent 5d6fd4ee6b
commit b9e9d38a9a
5 changed files with 60 additions and 15 deletions

View File

@ -3,4 +3,4 @@ httpport = 8080
runmode = dev
autorender = false
copyrequestbody = true
EnableDocs = false
enableadmin = true

15
controllers/ping.go Normal file
View File

@ -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>")
}

View File

@ -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{})
}

View File

@ -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>")
})
})
}

View File

@ -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)