diff --git a/config/config_test.go b/config/config_test.go index 6ce9c45..a4bc43a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -30,7 +30,10 @@ func TestWrongYAMLormat(t *testing.T) { } // clean up - defer os.Remove(filename) + defer func() { + err := os.Remove(filename) + assert.Nil(t, err) + }() // parse JSON format error _, err := LoadConfYaml(filename) diff --git a/gorush/log.go b/gorush/log.go index 22740f3..9673d26 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -67,11 +67,11 @@ func InitLog() error { } // set logger - if err := SetLogLevel(LogAccess, PushConf.Log.AccessLevel); err != nil { + if err = SetLogLevel(LogAccess, PushConf.Log.AccessLevel); err != nil { return errors.New("Set access log level error: " + err.Error()) } - if err := SetLogLevel(LogError, PushConf.Log.ErrorLevel); err != nil { + if err = SetLogLevel(LogError, PushConf.Log.ErrorLevel); err != nil { return errors.New("Set error log level error: " + err.Error()) } @@ -206,7 +206,7 @@ func getLogPushEntry(status, token string, req PushNotification, errPush error) errMsg = errPush.Error() } - if PushConf.Log.HideToken == true { + if PushConf.Log.HideToken { token = hideToken(token, 10) } diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index bb5d0fe..8b3720e 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -215,7 +215,7 @@ Retry: } } - if isError == true && retryCount < maxRetry { + if isError && retryCount < maxRetry { retryCount++ // resend fail token diff --git a/gorush/notification_apns_test.go b/gorush/notification_apns_test.go index 2874313..90cfe54 100644 --- a/gorush/notification_apns_test.go +++ b/gorush/notification_apns_test.go @@ -349,7 +349,8 @@ func TestDisabledIosNotifications(t *testing.T) { PushConf.Ios.Enabled = false PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" - InitAPNSClient() + err := InitAPNSClient() + assert.Nil(t, err) PushConf.Android.Enabled = true PushConf.Android.APIKey = os.Getenv("ANDROID_API_KEY") @@ -394,8 +395,8 @@ func TestAPNSClientDevHost(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.p12" - InitAPNSClient() - + err := InitAPNSClient() + assert.Nil(t, err) assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host) } @@ -405,8 +406,8 @@ func TestAPNSClientProdHost(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.Production = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" - InitAPNSClient() - + err := InitAPNSClient() + assert.Nil(t, err) assert.Equal(t, apns2.HostProduction, ApnsClient.Host) } @@ -415,8 +416,10 @@ func TestPushToIOS(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" - InitAPNSClient() - InitAppStatus() + err := InitAPNSClient() + assert.Nil(t, err) + err = InitAppStatus() + assert.Nil(t, err) req := PushNotification{ Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"}, diff --git a/gorush/notification_fcm.go b/gorush/notification_fcm.go index bd85e6a..0ac1311 100644 --- a/gorush/notification_fcm.go +++ b/gorush/notification_fcm.go @@ -141,7 +141,7 @@ Retry: LogPush(SucceededPush, req.Tokens[k], req, nil) } - if isError == true && retryCount < maxRetry { + if isError && retryCount < maxRetry { retryCount++ // resend fail token diff --git a/gorush/notification_test.go b/gorush/notification_test.go index fffd11d..f4d454d 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -29,7 +29,8 @@ func TestSenMultipleNotifications(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" - InitAPNSClient() + err := InitAPNSClient() + assert.Nil(t, err) PushConf.Android.Enabled = true PushConf.Android.APIKey = os.Getenv("ANDROID_API_KEY") @@ -63,7 +64,8 @@ func TestDisabledAndroidNotifications(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" - InitAPNSClient() + err := InitAPNSClient() + assert.Nil(t, err) PushConf.Android.Enabled = false PushConf.Android.APIKey = os.Getenv("ANDROID_API_KEY") @@ -97,7 +99,8 @@ func TestSyncModeForNotifications(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" - InitAPNSClient() + err := InitAPNSClient() + assert.Nil(t, err) PushConf.Android.Enabled = true PushConf.Android.APIKey = os.Getenv("ANDROID_API_KEY") diff --git a/gorush/status_test.go b/gorush/status_test.go index 0d77984..8190dd7 100644 --- a/gorush/status_test.go +++ b/gorush/status_test.go @@ -19,7 +19,8 @@ func TestStatForMemoryEngine(t *testing.T) { var val int64 PushConf.Stat.Engine = "memory" - InitAppStatus() + err := InitAppStatus() + assert.Nil(t, err) StatStorage.AddTotalCount(100) StatStorage.AddIosSuccess(200) @@ -61,7 +62,8 @@ func TestStatForRedisEngine(t *testing.T) { var val int64 PushConf.Stat.Engine = "redis" PushConf.Stat.Redis.Addr = "redis:6379" - InitAppStatus() + err := InitAppStatus() + assert.Nil(t, err) StatStorage.Init() StatStorage.Reset() @@ -87,7 +89,8 @@ func TestStatForRedisEngine(t *testing.T) { func TestDefaultEngine(t *testing.T) { var val int64 // defaul engine as memory - InitAppStatus() + err := InitAppStatus() + assert.Nil(t, err) StatStorage.Reset() @@ -137,7 +140,8 @@ func TestStatForBoltDBEngine(t *testing.T) { func TestStatForBuntDBEngine(t *testing.T) { var val int64 PushConf.Stat.Engine = "buntdb" - InitAppStatus() + err := InitAppStatus() + assert.Nil(t, err) StatStorage.Reset()