From b9e9d38a9aeae82bd34b93e60be29e9f315afa8a Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 24 Feb 2016 00:07:57 -0500 Subject: [PATCH] First endpoint: Ping --- conf/app.conf | 2 +- controllers/ping.go | 15 ++++++++++++ routers/router.go | 14 +----------- tests/controllers/ping_test.go | 42 ++++++++++++++++++++++++++++++++++ tests/default_test.go | 2 +- 5 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 controllers/ping.go create mode 100644 tests/controllers/ping_test.go diff --git a/conf/app.conf b/conf/app.conf index d3cbf4683..955df9ef1 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -3,4 +3,4 @@ httpport = 8080 runmode = dev autorender = false copyrequestbody = true -EnableDocs = false +enableadmin = true diff --git a/controllers/ping.go b/controllers/ping.go new file mode 100644 index 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("") +} + + + diff --git a/routers/router.go b/routers/router.go index 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.go new file mode 100644 index 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, "") + }) + + }) +} + diff --git a/tests/default_test.go b/tests/default_test.go index 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)