add api and push handler testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-01 10:35:04 +08:00
parent f380fdd324
commit 6994f7f3de
1 changed files with 35 additions and 0 deletions

View File

@ -6,8 +6,11 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"net/http" "net/http"
"testing" "testing"
"runtime"
) )
var go_version = runtime.Version()
func initTest() { func initTest() {
PushConf = BuildDefaultPushConf() PushConf = BuildDefaultPushConf()
PushConf.Core.Mode = "test" PushConf.Core.Mode = "test"
@ -28,3 +31,35 @@ func TestRootHandler(t *testing.T) {
assert.Equal(t, http.StatusOK, r.Code) 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)
})
}