From 2e3cc8e281237a27f99cd029fabbb0d84cb31dff Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 24 Jul 2017 21:41:21 +0800 Subject: [PATCH] fix: check return value (#256) * fix: check return value * fix testing Signed-off-by: Bo-Yi Wu --- gorush/notification_fcm.go | 2 +- gorush/notification_test.go | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/gorush/notification_fcm.go b/gorush/notification_fcm.go index af01de2..7538b35 100644 --- a/gorush/notification_fcm.go +++ b/gorush/notification_fcm.go @@ -126,5 +126,5 @@ Retry: goto Retry } - return !isError + return isError } diff --git a/gorush/notification_test.go b/gorush/notification_test.go index e9ed4f4..f844560 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -442,6 +442,7 @@ func TestPushToIOS(t *testing.T) { Message: "Welcome", } + // send fail isError := PushToIOS(req) assert.True(t, isError) } @@ -458,8 +459,9 @@ func TestPushToAndroidWrongAPIKey(t *testing.T) { Message: "Welcome", } - success := PushToAndroid(req) - assert.False(t, success) + // FCM server error: 401 error: 401 Unauthorized + err := PushToAndroid(req) + assert.False(t, err) } func TestPushToAndroidWrongToken(t *testing.T) { @@ -474,8 +476,8 @@ func TestPushToAndroidWrongToken(t *testing.T) { Message: "Welcome", } - success := PushToAndroid(req) - assert.False(t, success) + isError := PushToAndroid(req) + assert.True(t, isError) } func TestPushToAndroidRightTokenForJSONLog(t *testing.T) { @@ -494,8 +496,8 @@ func TestPushToAndroidRightTokenForJSONLog(t *testing.T) { Message: "Welcome", } - success := PushToAndroid(req) - assert.True(t, success) + isError := PushToAndroid(req) + assert.False(t, isError) } func TestPushToAndroidRightTokenForStringLog(t *testing.T) { @@ -512,8 +514,8 @@ func TestPushToAndroidRightTokenForStringLog(t *testing.T) { Message: "Welcome", } - success := PushToAndroid(req) - assert.False(t, success) + isError := PushToAndroid(req) + assert.True(t, isError) } func TestOverwriteAndroidAPIKey(t *testing.T) { @@ -532,8 +534,9 @@ func TestOverwriteAndroidAPIKey(t *testing.T) { APIKey: "1234", } - success := PushToAndroid(req) - assert.False(t, success) + // FCM server error: 401 error: 401 Unauthorized + err := PushToAndroid(req) + assert.False(t, err) } func TestSenMultipleNotifications(t *testing.T) { @@ -781,8 +784,8 @@ func TestCheckAndroidMessage(t *testing.T) { TimeToLive: &timeToLive, } - success := PushToAndroid(req) - assert.False(t, success) + err := PushToAndroid(req) + assert.False(t, err) } func TestSetProxyURL(t *testing.T) {