add ios certificate testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-01 23:06:29 +08:00
parent 238980ed95
commit fa22f2c655
2 changed files with 37 additions and 5 deletions

View File

@ -71,7 +71,7 @@ type RequestPushNotification struct {
IDs []uint64 `json:"seq_id,omitempty"` IDs []uint64 `json:"seq_id,omitempty"`
} }
func InitAPNSClient() { func InitAPNSClient() error {
if PushConf.Ios.Enabled { if PushConf.Ios.Enabled {
var err error var err error
@ -80,7 +80,7 @@ func InitAPNSClient() {
if err != nil { if err != nil {
log.Println("Cert Error:", err) log.Println("Cert Error:", err)
return return err
} }
if PushConf.Ios.Production { if PushConf.Ios.Production {
@ -89,6 +89,8 @@ func InitAPNSClient() {
ApnsClient = apns.NewClient(CertificatePemIos).Development() ApnsClient = apns.NewClient(CertificatePemIos).Development()
} }
} }
return nil
} }
func pushNotification(notification RequestPushNotification) bool { func pushNotification(notification RequestPushNotification) bool {
@ -221,8 +223,6 @@ func pushNotificationIos(req RequestPushNotification) bool {
if res.Sent() { if res.Sent() {
log.Println("APNs ID:", res.ApnsID) log.Println("APNs ID:", res.ApnsID)
return true
} }
} }

View File

@ -89,10 +89,42 @@ func TestDisabledIosPushHandler(t *testing.T) {
}) })
} }
func TestIosPushHandler(t *testing.T) { func TestMissingIosCertificate(t *testing.T) {
initTest() initTest()
PushConf.Ios.Enabled = true PushConf.Ios.Enabled = true
PushConf.Ios.PemKeyPath = "test"
err := InitAPNSClient()
assert.Error(t, err)
}
func TestIosPushDevelopment(t *testing.T) {
initTest()
PushConf.Ios.Enabled = true
PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem"
InitAPNSClient()
r := gofight.New()
r.POST("/api/push").
SetJSON(gofight.D{
"tokens": []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"},
"platform": 1,
"message": "Welcome",
}).
Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) {
assert.Equal(t, http.StatusOK, r.Code)
})
}
func TestIosPushProduction(t *testing.T) {
initTest()
PushConf.Ios.Enabled = true
PushConf.Ios.Production = true
PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem"
InitAPNSClient() InitAPNSClient()