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.
This commit is contained in:
ahp
2026-10-11 12:04:41 +03:30
parent e412819d48
commit ae37b98ef8
4 changed files with 396 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
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")
}
}