add ios certificate testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
238980ed95
commit
fa22f2c655
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue