add androdi and ios testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
7002c4008c
commit
9097631c92
|
@ -120,12 +120,12 @@ func pushNotification(notification RequestPushNotification) bool {
|
|||
if !PushConf.Ios.Enabled {
|
||||
return false
|
||||
}
|
||||
go pushNotificationIos(notification)
|
||||
go PushToIOS(notification)
|
||||
case PlatFormAndroid:
|
||||
if !PushConf.Android.Enabled {
|
||||
return false
|
||||
}
|
||||
go pushNotificationAndroid(notification)
|
||||
go PushToAndroid(notification)
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -222,7 +222,7 @@ func GetIOSNotification(req RequestPushNotification) *apns.Notification {
|
|||
return notification
|
||||
}
|
||||
|
||||
func pushNotificationIos(req RequestPushNotification) bool {
|
||||
func PushToIOS(req RequestPushNotification) bool {
|
||||
|
||||
notification := GetIOSNotification(req)
|
||||
|
||||
|
@ -299,7 +299,7 @@ func GetAndroidNotification(req RequestPushNotification) gcm.HttpMessage {
|
|||
return notification
|
||||
}
|
||||
|
||||
func pushNotificationAndroid(req RequestPushNotification) bool {
|
||||
func PushToAndroid(req RequestPushNotification) bool {
|
||||
|
||||
notification := GetAndroidNotification(req)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"log"
|
||||
"testing"
|
||||
"os"
|
||||
)
|
||||
|
||||
func TestDisabledAndroidIosConf(t *testing.T) {
|
||||
|
@ -203,3 +204,72 @@ func TestAndroidNotificationStructure(t *testing.T) {
|
|||
assert.Equal(t, test, notification.Notification.Title)
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue