Files
ahp ae37b98ef8 feat(config): load ntfy client.yml and resolve topic origins
Parse the official ntfy client configuration, apply command-line overrides, and turn short names, host/topic pairs, and absolute URLs into an origin and topic name.
2026-10-11 12:04:41 +03:30

28 lines
838 B
Go

package config
import "testing"
func TestResolve(t *testing.T) {
cases := []struct {
topic, host, origin, name string
}{
{"alerts", "https://ntfy.example", "https://ntfy.example", "alerts"},
{"alerts", "https://ntfy.example/", "https://ntfy.example", "alerts"},
{"https://ntfy.example/alerts", "", "https://ntfy.example", "alerts"},
{"ntfy.example/alerts", "", "https://ntfy.example", "alerts"},
{"https://ntfy.example/base/alerts", "", "https://ntfy.example/base", "alerts"},
}
for _, tc := range cases {
origin, name, err := Resolve(tc.topic, tc.host)
if err != nil {
t.Fatalf("%s: %v", tc.topic, err)
}
if origin != tc.origin || name != tc.name {
t.Fatalf("%s: got %s %s", tc.topic, origin, name)
}
}
if _, _, err := Resolve("alerts", ""); err == nil {
t.Fatal("expected missing host error")
}
}