mirror of
https://github.com/nikoksr/notify.git
synced 2024-11-24 08:22:18 +02:00
test: fill gaps in library root
This commit is contained in:
parent
23b572dfb2
commit
0dac5dc6af
@ -1,6 +1,7 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@ -97,3 +98,21 @@ func TestNewWithServices(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
if err := Send(ctx, "subject", "message"); err != nil {
|
||||
t.Errorf("Send() with no receivers returned error: %v", err)
|
||||
}
|
||||
|
||||
UseServices(mail.New("", ""), nil)
|
||||
if len(std.notifiers) != 1 {
|
||||
t.Errorf("UseServices(mail.New()) was expected to have 1 notifier but had %d", len(std.notifiers))
|
||||
}
|
||||
|
||||
if err := Send(ctx, "subject", "message"); err == nil {
|
||||
t.Error("Send() with invalid mail returned no error")
|
||||
}
|
||||
}
|
||||
|
21
send_test.go
21
send_test.go
@ -38,4 +38,25 @@ func TestNotifySend(t *testing.T) {
|
||||
if err := n.Send(ctx, "subject", "message"); err == nil {
|
||||
t.Errorf("Send() invalid mail returned no error: %v", err)
|
||||
}
|
||||
|
||||
// After disabling the Notifier, Send() should return silently.
|
||||
n.WithOptions(Disable)
|
||||
|
||||
if err := n.Send(ctx, "subject", "message"); err != nil {
|
||||
t.Errorf("Send() of disabled Notifier returned error: %v", err)
|
||||
}
|
||||
|
||||
n.WithOptions(Enable)
|
||||
|
||||
// Smuggle in a nil service. This usually never happens, since UseServices filters out nil services. But, it's good
|
||||
// to test anyway.
|
||||
n.notifiers = make([]Notifier, 0)
|
||||
n.notifiers = append(n.notifiers, nil)
|
||||
|
||||
if err := n.Send(ctx, "subject", "message"); err != nil {
|
||||
t.Errorf("Send() of disabled Notifier returned no error: %v", err)
|
||||
}
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Send() with nil service panicked: %v", r)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user