add api and push handler testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
f380fdd324
commit
6994f7f3de
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue