@@ -288,19 +288,21 @@ func pushNotificationAndroid(req RequestPushNotification) bool {
|
||||
|
||||
res, err := gcm.SendHttp(PushConf.Android.ApiKey, notification)
|
||||
|
||||
log.Printf("Success count: %d, Failure count: %d", res.Success, res.Failure)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Println("GCM Server Error Message: " + err.Error())
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if res.Error != "" {
|
||||
log.Println("GCM Error Message: " + res.Error)
|
||||
log.Println("GCM Http Error Message: " + res.Error)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if res.Success > 0 {
|
||||
log.Printf("Success count: %d, Failure count: %d", res.Success, res.Failure)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
"testing"
|
||||
"os"
|
||||
)
|
||||
|
||||
var go_version = runtime.Version()
|
||||
@@ -16,6 +17,10 @@ func initTest() {
|
||||
PushConf.Core.Mode = "test"
|
||||
}
|
||||
|
||||
func TestPrintGoPushVersion(t *testing.T) {
|
||||
PrintGoPushVersion()
|
||||
}
|
||||
|
||||
func TestRootHandler(t *testing.T) {
|
||||
initTest()
|
||||
|
||||
@@ -124,10 +129,11 @@ func TestDisabledAndroidPushHandler(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAndroidPushHandler(t *testing.T) {
|
||||
func TestAndroidWrongAPIKey(t *testing.T) {
|
||||
initTest()
|
||||
|
||||
PushConf.Android.Enabled = true
|
||||
PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY") + "a"
|
||||
|
||||
r := gofight.New()
|
||||
|
||||
@@ -142,3 +148,45 @@ func TestAndroidPushHandler(t *testing.T) {
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAndroidWrongToken(t *testing.T) {
|
||||
initTest()
|
||||
|
||||
PushConf.Android.Enabled = true
|
||||
PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY")
|
||||
|
||||
r := gofight.New()
|
||||
|
||||
r.POST("/api/push").
|
||||
SetJSON(gofight.D{
|
||||
"tokens": []string{"aaaaaa", "bbbbb"},
|
||||
"platform": 2,
|
||||
"message": "Welcome",
|
||||
}).
|
||||
Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) {
|
||||
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAndroidRightToken(t *testing.T) {
|
||||
initTest()
|
||||
|
||||
PushConf.Android.Enabled = true
|
||||
PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY")
|
||||
|
||||
android_token := os.Getenv("ANDROID_TEST_TOKEN")
|
||||
|
||||
r := gofight.New()
|
||||
|
||||
r.POST("/api/push").
|
||||
SetJSON(gofight.D{
|
||||
"tokens": []string{android_token, "bbbbb"},
|
||||
"platform": 2,
|
||||
"message": "Welcome",
|
||||
}).
|
||||
Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) {
|
||||
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user