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:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user