Files
lazyntfy/internal/config/topic_test.go
T

28 lines
838 B
Go
Raw Normal View History

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")
}
}