2016-03-31 16:35:53 +00:00
|
|
|
package gopush
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/appleboy/gofight"
|
|
|
|
"github.com/buger/jsonparser"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2016-04-01 02:35:04 +00:00
|
|
|
"runtime"
|
2016-03-31 16:35:53 +00:00
|
|
|
)
|
|
|
|
|
2016-04-01 02:35:04 +00:00
|
|
|
var go_version = runtime.Version()
|
|
|
|
|
2016-03-31 16:35:53 +00:00
|
|
|
func initTest() {
|
|
|
|
PushConf = BuildDefaultPushConf()
|
2016-04-01 01:53:10 +00:00
|
|
|
PushConf.Core.Mode = "test"
|
2016-03-31 16:35:53 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 01:53:10 +00:00
|
|
|
func TestRootHandler(t *testing.T) {
|
2016-03-31 16:35:53 +00:00
|
|
|
initTest()
|
|
|
|
|
|
|
|
r := gofight.New()
|
|
|
|
|
|
|
|
r.GET("/").
|
|
|
|
Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) {
|
|
|
|
data := []byte(r.Body.String())
|
|
|
|
|
|
|
|
value, _ := jsonparser.GetString(data, "text")
|
|
|
|
|
|
|
|
assert.Equal(t, "Welcome to notification server.", value)
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
}
|
2016-04-01 02:35:04 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|