From 6994f7f3de6c94865babd687071312b5fea06507 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 10:35:04 +0800 Subject: [PATCH] add api and push handler testing. Signed-off-by: Bo-Yi Wu --- gorush/server_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gorush/server_test.go b/gorush/server_test.go index 00670ea..596cd92 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -6,8 +6,11 @@ import ( "github.com/stretchr/testify/assert" "net/http" "testing" + "runtime" ) +var go_version = runtime.Version() + func initTest() { PushConf = BuildDefaultPushConf() PushConf.Core.Mode = "test" @@ -28,3 +31,35 @@ func TestRootHandler(t *testing.T) { assert.Equal(t, http.StatusOK, r.Code) }) } + +func TestAPIStatusHandler(t *testing.T) { + initTest() + + r := gofight.New() + + r.GET("/api/status"). + Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) { + data := []byte(r.Body.String()) + + value, _ := jsonparser.GetString(data, "go_version") + + assert.Equal(t, go_version, value) + assert.Equal(t, http.StatusOK, r.Code) + }) +} + +func TestPushHandler(t *testing.T) { + initTest() + + r := gofight.New() + + // missing some parameter. + r.POST("/api/push"). + SetJSON(gofight.D{ + "platform": 1, + }). + Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) { + + assert.Equal(t, http.StatusBadRequest, r.Code) + }) +}