fix(notifications): test handle unsupported type (#841)

* bugfix: nil pointer dereference

if agent variable is nil when the Send method is called, will crash.

* refactor: return early.

* refactor: idiomatic solution.

---------

Co-authored-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2023-04-17 02:44:07 +10:00 committed by GitHub
parent fe71dfc3af
commit e0aaa0bcab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ import (
"github.com/autobrr/autobrr/internal/domain" "github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/internal/logger" "github.com/autobrr/autobrr/internal/logger"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/rs/zerolog" "github.com/rs/zerolog"
) )
@ -235,9 +236,12 @@ func (s *service) Test(ctx context.Context, notification domain.Notification) er
agent = NewNotifiarrSender(s.log, notification) agent = NewNotifiarrSender(s.log, notification)
case domain.NotificationTypeTelegram: case domain.NotificationTypeTelegram:
agent = NewTelegramSender(s.log, notification) agent = NewTelegramSender(s.log, notification)
default:
s.log.Error().Msgf("unsupported notification type: %v", notification.Type)
return errors.New("unsupported notification type")
} }
g, ctx := errgroup.WithContext(ctx) g, _ := errgroup.WithContext(ctx)
for _, event := range events { for _, event := range events {
e := event e := event