add androdi and ios testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-03 17:57:04 +08:00
parent 7002c4008c
commit 9097631c92
2 changed files with 74 additions and 4 deletions

View File

@ -120,12 +120,12 @@ func pushNotification(notification RequestPushNotification) bool {
if !PushConf.Ios.Enabled { if !PushConf.Ios.Enabled {
return false return false
} }
go pushNotificationIos(notification) go PushToIOS(notification)
case PlatFormAndroid: case PlatFormAndroid:
if !PushConf.Android.Enabled { if !PushConf.Android.Enabled {
return false return false
} }
go pushNotificationAndroid(notification) go PushToAndroid(notification)
} }
return true return true
@ -222,7 +222,7 @@ func GetIOSNotification(req RequestPushNotification) *apns.Notification {
return notification return notification
} }
func pushNotificationIos(req RequestPushNotification) bool { func PushToIOS(req RequestPushNotification) bool {
notification := GetIOSNotification(req) notification := GetIOSNotification(req)
@ -299,7 +299,7 @@ func GetAndroidNotification(req RequestPushNotification) gcm.HttpMessage {
return notification return notification
} }
func pushNotificationAndroid(req RequestPushNotification) bool { func PushToAndroid(req RequestPushNotification) bool {
notification := GetAndroidNotification(req) notification := GetAndroidNotification(req)

View File

@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"log" "log"
"testing" "testing"
"os"
) )
func TestDisabledAndroidIosConf(t *testing.T) { func TestDisabledAndroidIosConf(t *testing.T) {
@ -203,3 +204,72 @@ func TestAndroidNotificationStructure(t *testing.T) {
assert.Equal(t, test, notification.Notification.Title) assert.Equal(t, test, notification.Notification.Title)
assert.Equal(t, "Welcome", notification.Notification.Body) assert.Equal(t, "Welcome", notification.Notification.Body)
} }
func TestPushToIOS(t *testing.T) {
PushConf = BuildDefaultPushConf()
PushConf.Ios.Enabled = true
PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem"
InitAPNSClient()
req := RequestPushNotification{
Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"},
Platform: 1,
Message: "Welcome",
}
success := PushToIOS(req)
assert.False(t, success)
}
func TestPushToAndroidWrongAPIKey(t *testing.T) {
PushConf = BuildDefaultPushConf()
PushConf.Android.Enabled = true
PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY") + "a"
req := RequestPushNotification{
Tokens: []string{"aaaaaa", "bbbbb"},
Platform: 2,
Message: "Welcome",
}
success := PushToAndroid(req)
assert.False(t, success)
}
func TestPushToAndroidWrongToken(t *testing.T) {
PushConf = BuildDefaultPushConf()
PushConf.Android.Enabled = true
PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY")
req := RequestPushNotification{
Tokens: []string{"aaaaaa", "bbbbb"},
Platform: 2,
Message: "Welcome",
}
success := PushToAndroid(req)
assert.True(t, success)
}
func TestPushToAndroidRightToken(t *testing.T) {
PushConf = BuildDefaultPushConf()
PushConf.Android.Enabled = true
PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY")
android_token := os.Getenv("ANDROID_TEST_TOKEN")
req := RequestPushNotification{
Tokens: []string{android_token, "bbbbb"},
Platform: 2,
Message: "Welcome",
}
success := PushToAndroid(req)
assert.True(t, success)
}