From fa22f2c6555e50f73d27c3409f1fda44bec9ddbe Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 23:06:29 +0800 Subject: [PATCH] add ios certificate testing. Signed-off-by: Bo-Yi Wu --- gorush/notification.go | 8 ++++---- gorush/server_test.go | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gorush/notification.go b/gorush/notification.go index 35aa1f6..ff0ac79 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -71,7 +71,7 @@ type RequestPushNotification struct { IDs []uint64 `json:"seq_id,omitempty"` } -func InitAPNSClient() { +func InitAPNSClient() error { if PushConf.Ios.Enabled { var err error @@ -80,7 +80,7 @@ func InitAPNSClient() { if err != nil { log.Println("Cert Error:", err) - return + return err } if PushConf.Ios.Production { @@ -89,6 +89,8 @@ func InitAPNSClient() { ApnsClient = apns.NewClient(CertificatePemIos).Development() } } + + return nil } func pushNotification(notification RequestPushNotification) bool { @@ -221,8 +223,6 @@ func pushNotificationIos(req RequestPushNotification) bool { if res.Sent() { log.Println("APNs ID:", res.ApnsID) - - return true } } diff --git a/gorush/server_test.go b/gorush/server_test.go index 1296dd5..11019c4 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -89,10 +89,42 @@ func TestDisabledIosPushHandler(t *testing.T) { }) } -func TestIosPushHandler(t *testing.T) { +func TestMissingIosCertificate(t *testing.T) { initTest() 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" InitAPNSClient()