mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 18:19:07 +01:00
Stream stdout and stderr into an exact byte counter instead of a growing CombinedOutput buffer. Preserve arguments, context cancellation, native errors, safe diagnostic counts and delivery verdicts. Exercise large mixed output and the real firing, recovery and Test senders with owned subprocesses. Change-source: pulse-maintainer
100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
package notifications
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestSendAppriseViaCLINoTargets(t *testing.T) {
|
|
nm := NewNotificationManager("")
|
|
defer nm.Stop()
|
|
|
|
err := nm.sendAppriseViaCLI(AppriseConfig{
|
|
CLIPath: "apprise",
|
|
TimeoutSeconds: 1,
|
|
}, "title", "body")
|
|
if err == nil {
|
|
t.Fatalf("expected error when no targets configured")
|
|
}
|
|
}
|
|
|
|
func TestSendAppriseViaCLIExecError(t *testing.T) {
|
|
nm := NewNotificationManager("")
|
|
defer nm.Stop()
|
|
|
|
nm.appriseExec = func(ctx context.Context, args []string) (int64, error) {
|
|
return int64(len("boom")), errors.New("exec failed")
|
|
}
|
|
|
|
err := nm.sendAppriseViaCLI(AppriseConfig{
|
|
CLIPath: "apprise",
|
|
TimeoutSeconds: 1,
|
|
Targets: []string{"discord://token"},
|
|
}, "title", "body")
|
|
if err == nil {
|
|
t.Fatalf("expected exec error")
|
|
}
|
|
}
|
|
|
|
func TestSendAppriseViaCLISuccess(t *testing.T) {
|
|
nm := NewNotificationManager("")
|
|
defer nm.Stop()
|
|
|
|
nm.appriseExec = func(ctx context.Context, args []string) (int64, error) {
|
|
return int64(len("ok")), nil
|
|
}
|
|
|
|
err := nm.sendAppriseViaCLI(AppriseConfig{
|
|
CLIPath: "apprise",
|
|
TimeoutSeconds: 1,
|
|
Targets: []string{"discord://token"},
|
|
}, "title", "body")
|
|
if err != nil {
|
|
t.Fatalf("expected success, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSendAppriseViaCLISuccessNoOutput(t *testing.T) {
|
|
nm := NewNotificationManager("")
|
|
defer nm.Stop()
|
|
|
|
nm.appriseExec = func(ctx context.Context, args []string) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
err := nm.sendAppriseViaCLI(AppriseConfig{
|
|
CLIPath: "apprise",
|
|
TimeoutSeconds: 1,
|
|
Targets: []string{"discord://token"},
|
|
}, "title", "body")
|
|
if err != nil {
|
|
t.Fatalf("expected success, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSendAppriseViaCLIPreservesTelegramTopicTarget(t *testing.T) {
|
|
nm := NewNotificationManager("")
|
|
defer nm.Stop()
|
|
|
|
const topicTarget = "tgram://bot-token/-1001234567890:42"
|
|
var receivedArgs []string
|
|
nm.appriseExec = func(ctx context.Context, args []string) (int64, error) {
|
|
receivedArgs = slices.Clone(args)
|
|
return 0, nil
|
|
}
|
|
|
|
err := nm.sendAppriseViaCLI(AppriseConfig{
|
|
CLIPath: "apprise",
|
|
TimeoutSeconds: 1,
|
|
Targets: []string{topicTarget},
|
|
}, "title", "body")
|
|
if err != nil {
|
|
t.Fatalf("expected Telegram topic target delivery to succeed, got %v", err)
|
|
}
|
|
if len(receivedArgs) == 0 || receivedArgs[len(receivedArgs)-1] != topicTarget {
|
|
t.Fatalf("expected Telegram topic target to be preserved as one CLI argument, got %#v", receivedArgs)
|
|
}
|
|
}
|