From bb55f909f9f57e095f4c2b81e9295ccdeedaf54c Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Thu, 12 Sep 2019 16:50:36 +0200 Subject: [PATCH 1/4] add New options --- messaging/messaging.go | 51 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/messaging/messaging.go b/messaging/messaging.go index 9d892b16..c9858328 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -262,18 +262,45 @@ func (a *AndroidConfig) UnmarshalJSON(b []byte) error { // AndroidNotification is a notification to send to Android devices. type AndroidNotification struct { - Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type - Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type - Icon string `json:"icon,omitempty"` - Color string `json:"color,omitempty"` // notification color in #RRGGBB format - Sound string `json:"sound,omitempty"` - Tag string `json:"tag,omitempty"` - ClickAction string `json:"click_action,omitempty"` - BodyLocKey string `json:"body_loc_key,omitempty"` - BodyLocArgs []string `json:"body_loc_args,omitempty"` - TitleLocKey string `json:"title_loc_key,omitempty"` - TitleLocArgs []string `json:"title_loc_args,omitempty"` - ChannelID string `json:"channel_id,omitempty"` + Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type + Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type + Icon string `json:"icon,omitempty"` + Color string `json:"color,omitempty"` // notification color in #RRGGBB format + Sound string `json:"sound,omitempty"` + Tag string `json:"tag,omitempty"` + ClickAction string `json:"click_action,omitempty"` + BodyLocKey string `json:"body_loc_key,omitempty"` + BodyLocArgs []string `json:"body_loc_args,omitempty"` + TitleLocKey string `json:"title_loc_key,omitempty"` + TitleLocArgs []string `json:"title_loc_args,omitempty"` + ChannelID string `json:"channel_id,omitempty"` + Ticker string `json:"ticker,omitempty"` + Sticky bool `json:"sticky,omitempty"` + EventTime *time.Time `json:"event_time,omitempty"` + LocalOnly bool `json:"local_only,omitempty"` + Priority string `json:"priority,omitempty"` + DefaultSound bool `json:"default_sound,omitempty"` + DefaultVibrateTimings bool `json:"default_vibrate_timings,omitempty"` + DefaultLightSettings bool `json:"default_light_settings,omitempty"` + VibrateTimings []*time.Duration `json:"vibrate_timings,omitempty"` + Visibility string `json:"visibility,omitempty"` + NotificationCount float64 `json:"notification_count,omitempty"` + LightSettings *LightSettings `json:"light_settings,omitempty"` +} + +// LightSettings is Settings to control notification LED. +type LightSettings struct { + Color *Color `json:"color,omitempty"` + LightOnDuration *time.Duration `json:"light_on_duration,omitempty"` + LightOffDuration *time.Duration `json:"light_off_duration,omitempty"` +} + +// Color represents a color in the RGBA color space. +type Color struct { + Red float64 `json:"red,omitempty"` + Green float64 `json:"green,omitempty"` + Blue float64 `json:"blue,omitempty"` + Alpha float64 `json:"alpha,omitempty"` } // AndroidFCMOptions contains additional options for features provided by the FCM Android SDK. From ad3f0e759f1df39e0319360f22d95635f8461fe6 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Thu, 12 Sep 2019 17:30:45 +0200 Subject: [PATCH 2/4] inline error check --- auth/email_action_links_test.go | 13 +++++-------- auth/user_mgt_test.go | 9 +++------ internal/http_client_test.go | 3 +-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/auth/email_action_links_test.go b/auth/email_action_links_test.go index 45082926..f39dbf15 100644 --- a/auth/email_action_links_test.go +++ b/auth/email_action_links_test.go @@ -204,18 +204,16 @@ func TestEmailSignInLink(t *testing.T) { func TestEmailActionLinkNoEmail(t *testing.T) { client := &Client{} - _, err := client.EmailVerificationLink(context.Background(), "") - if err == nil { + + if _, err := client.EmailVerificationLink(context.Background(), ""); err == nil { t.Errorf("EmailVerificationLink('') = nil; want error") } - _, err = client.PasswordResetLink(context.Background(), "") - if err == nil { + if _, err := client.PasswordResetLink(context.Background(), ""); err == nil { t.Errorf("PasswordResetLink('') = nil; want error") } - _, err = client.EmailSignInLink(context.Background(), "", testActionCodeSettings) - if err == nil { + if _, err := client.EmailSignInLink(context.Background(), "", testActionCodeSettings); err == nil { t.Errorf("EmailSignInLink('') = nil; want error") } } @@ -252,8 +250,7 @@ func TestEmailSignInLinkInvalidSettings(t *testing.T) { func TestEmailSignInLinkNoSettings(t *testing.T) { client := &Client{} - _, err := client.EmailSignInLink(context.Background(), testEmail, nil) - if err == nil { + if _, err := client.EmailSignInLink(context.Background(), testEmail, nil); err == nil { t.Errorf("EmailSignInLink(nil) = %v; want = error", err) } } diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go index c710e7ab..c0bdeb53 100644 --- a/auth/user_mgt_test.go +++ b/auth/user_mgt_test.go @@ -1123,8 +1123,7 @@ func TestSessionCookieWithoutProjectID(t *testing.T) { func TestSessionCookieWithoutIDToken(t *testing.T) { client := &Client{} - _, err := client.SessionCookie(context.Background(), "", 10*time.Minute) - if err == nil { + if _, err := client.SessionCookie(context.Background(), "", 10*time.Minute); err == nil { t.Errorf("CreateSessionCookie('') = nil; want error") } } @@ -1132,8 +1131,7 @@ func TestSessionCookieWithoutIDToken(t *testing.T) { func TestSessionCookieShortExpiresIn(t *testing.T) { client := &Client{} lessThanFiveMins := 5*time.Minute - time.Second - _, err := client.SessionCookie(context.Background(), "idToken", lessThanFiveMins) - if err == nil { + if _, err := client.SessionCookie(context.Background(), "idToken", lessThanFiveMins); err == nil { t.Errorf("SessionCookie(< 5 mins) = nil; want error") } } @@ -1141,8 +1139,7 @@ func TestSessionCookieShortExpiresIn(t *testing.T) { func TestSessionCookieLongExpiresIn(t *testing.T) { client := &Client{} moreThanTwoWeeks := 14*24*time.Hour + time.Second - _, err := client.SessionCookie(context.Background(), "idToken", moreThanTwoWeeks) - if err == nil { + if _, err := client.SessionCookie(context.Background(), "idToken", moreThanTwoWeeks); err == nil { t.Errorf("SessionCookie(> 14 days) = nil; want error") } } diff --git a/internal/http_client_test.go b/internal/http_client_test.go index e5db3a13..4d5cfd56 100644 --- a/internal/http_client_test.go +++ b/internal/http_client_test.go @@ -486,8 +486,7 @@ func TestInvalidURL(t *testing.T) { URL: "http://localhost:250/mock.url", } client := &HTTPClient{Client: http.DefaultClient} - _, err := client.Do(context.Background(), req) - if err == nil { + if _, err := client.Do(context.Background(), req); err == nil { t.Errorf("Send() = nil; want error") } } From 8f1eb742925603acd5b0aee9a04df3330ce5ddc9 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Thu, 12 Sep 2019 17:35:26 +0200 Subject: [PATCH 3/4] inline error check --- messaging/messaging_batch_test.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/messaging/messaging_batch_test.go b/messaging/messaging_batch_test.go index 3d07902f..d7394281 100644 --- a/messaging/messaging_batch_test.go +++ b/messaging/messaging_batch_test.go @@ -359,9 +359,7 @@ func TestSendAllNonMultipartResponse(t *testing.T) { t.Fatal(err) } client.batchEndpoint = ts.URL - - _, err = client.SendAll(ctx, testMessages) - if err == nil { + if _, err = client.SendAll(ctx, testMessages); err == nil { t.Fatal("SendAll() = nil; want = error") } } @@ -379,9 +377,7 @@ func TestSendAllMalformedContentType(t *testing.T) { t.Fatal(err) } client.batchEndpoint = ts.URL - - _, err = client.SendAll(ctx, testMessages) - if err == nil { + if _, err = client.SendAll(ctx, testMessages); err == nil { t.Fatal("SendAll() = nil; want = error") } } @@ -405,9 +401,7 @@ func TestSendAllMalformedMultipartResponse(t *testing.T) { t.Fatal(err) } client.batchEndpoint = ts.URL - - _, err = client.SendAll(ctx, testMessages) - if err == nil { + if _, err = client.SendAll(ctx, testMessages); err == nil { t.Fatal("SendAll() = nil; want = error") } } From 72e2631913b67e9ee340a72a3c3d6bac1fa93d71 Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Tue, 5 Nov 2019 09:48:34 +0100 Subject: [PATCH 4/4] revert additions to the FCM API --- messaging/messaging.go | 51 ++++++++++-------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/messaging/messaging.go b/messaging/messaging.go index c9858328..9d892b16 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -262,45 +262,18 @@ func (a *AndroidConfig) UnmarshalJSON(b []byte) error { // AndroidNotification is a notification to send to Android devices. type AndroidNotification struct { - Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type - Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type - Icon string `json:"icon,omitempty"` - Color string `json:"color,omitempty"` // notification color in #RRGGBB format - Sound string `json:"sound,omitempty"` - Tag string `json:"tag,omitempty"` - ClickAction string `json:"click_action,omitempty"` - BodyLocKey string `json:"body_loc_key,omitempty"` - BodyLocArgs []string `json:"body_loc_args,omitempty"` - TitleLocKey string `json:"title_loc_key,omitempty"` - TitleLocArgs []string `json:"title_loc_args,omitempty"` - ChannelID string `json:"channel_id,omitempty"` - Ticker string `json:"ticker,omitempty"` - Sticky bool `json:"sticky,omitempty"` - EventTime *time.Time `json:"event_time,omitempty"` - LocalOnly bool `json:"local_only,omitempty"` - Priority string `json:"priority,omitempty"` - DefaultSound bool `json:"default_sound,omitempty"` - DefaultVibrateTimings bool `json:"default_vibrate_timings,omitempty"` - DefaultLightSettings bool `json:"default_light_settings,omitempty"` - VibrateTimings []*time.Duration `json:"vibrate_timings,omitempty"` - Visibility string `json:"visibility,omitempty"` - NotificationCount float64 `json:"notification_count,omitempty"` - LightSettings *LightSettings `json:"light_settings,omitempty"` -} - -// LightSettings is Settings to control notification LED. -type LightSettings struct { - Color *Color `json:"color,omitempty"` - LightOnDuration *time.Duration `json:"light_on_duration,omitempty"` - LightOffDuration *time.Duration `json:"light_off_duration,omitempty"` -} - -// Color represents a color in the RGBA color space. -type Color struct { - Red float64 `json:"red,omitempty"` - Green float64 `json:"green,omitempty"` - Blue float64 `json:"blue,omitempty"` - Alpha float64 `json:"alpha,omitempty"` + Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type + Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type + Icon string `json:"icon,omitempty"` + Color string `json:"color,omitempty"` // notification color in #RRGGBB format + Sound string `json:"sound,omitempty"` + Tag string `json:"tag,omitempty"` + ClickAction string `json:"click_action,omitempty"` + BodyLocKey string `json:"body_loc_key,omitempty"` + BodyLocArgs []string `json:"body_loc_args,omitempty"` + TitleLocKey string `json:"title_loc_key,omitempty"` + TitleLocArgs []string `json:"title_loc_args,omitempty"` + ChannelID string `json:"channel_id,omitempty"` } // AndroidFCMOptions contains additional options for features provided by the FCM Android SDK.