log-guardian/internal/alerts/alerts_test.go
WayfinderAK 6f7549d439
All checks were successful
build-image / docker (push) Successful in 53s
Implement phase 1 foundations
2026-07-03 20:14:06 -08:00

32 lines
959 B
Go

package alerts
import (
"net/http"
"net/http/httptest"
"testing"
"gitea.wayfinderak.com/wayfinderak/log-guardian/internal/analysis"
"gitea.wayfinderak.com/wayfinderak/log-guardian/internal/store"
)
func TestNtfyDelivery(t *testing.T) {
var gotAuth string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/alerts" {
t.Fatalf("unexpected path %s", r.URL.Path)
}
gotAuth = r.Header.Get("Authorization")
w.WriteHeader(http.StatusNoContent)
}))
defer ts.Close()
d := NewDispatcher()
_, err := d.Send(t.Context(), store.Rule{Name: "API", Severity: "warning"}, analysis.Finding{Summary: "failed"}, []store.AlertChannel{{ID: "c1", Name: "ntfy", Type: "ntfy", Enabled: true, Params: map[string]string{"server_url": ts.URL, "topic": "alerts", "token": "secret"}}})
if err != nil {
t.Fatal(err)
}
if gotAuth != "Bearer secret" {
t.Fatalf("missing auth header: %q", gotAuth)
}
}