Avoid panic when push messages are empty or nil (#13751)

Этот коммит содержится в:
Mario de Frutos Dieguez
2020-01-29 10:08:27 +01:00
коммит произвёл GitHub
родитель 3049378506
Коммит 682a1d5d15
7 изменённых файлов: 137 добавлений и 13 удалений

Просмотреть файл

@@ -11,11 +11,49 @@ import (
)
func TestPushNotification(t *testing.T) {
msg := PushNotification{Platform: "test"}
json := msg.ToJson()
result := PushNotificationFromJson(strings.NewReader(json))
t.Run("should build a push notification from JSON", func(t *testing.T) {
msg := PushNotification{Platform: "test"}
json := msg.ToJson()
result, err := PushNotificationFromJson(strings.NewReader(json))
require.Equal(t, msg.Platform, result.Platform, "Ids do not match")
require.Nil(t, err)
require.Equal(t, msg.Platform, result.Platform, "ids do not match")
})
t.Run("should throw an error when the message is nil", func(t *testing.T) {
_, err := PushNotificationFromJson(nil)
require.NotNil(t, err)
require.Equal(t, "push notification data can't be nil", err.Error())
})
t.Run("should throw an error when the message parsing fails", func(t *testing.T) {
_, err := PushNotificationFromJson(strings.NewReader(""))
require.NotNil(t, err)
require.Equal(t, "EOF", err.Error())
})
}
func TestPushNotificationAck(t *testing.T) {
t.Run("should build a push notification ack from JSON", func(t *testing.T) {
msg := PushNotificationAck{ClientPlatform: "test"}
json := msg.ToJson()
result, err := PushNotificationAckFromJson(strings.NewReader(json))
require.Nil(t, err)
require.Equal(t, msg.ClientPlatform, result.ClientPlatform, "ids do not match")
})
t.Run("should throw an error when the message is nil", func(t *testing.T) {
_, err := PushNotificationAckFromJson(nil)
require.NotNil(t, err)
require.Equal(t, "push notification data can't be nil", err.Error())
})
t.Run("should throw an error when the message parsing fails", func(t *testing.T) {
_, err := PushNotificationAckFromJson(strings.NewReader(""))
require.NotNil(t, err)
require.Equal(t, "EOF", err.Error())
})
}
func TestPushNotificationDeviceId(t *testing.T) {