31 lines
847 B
Go
31 lines
847 B
Go
package remnawave
|
|
|
|
import "testing"
|
|
|
|
func TestPublicSubURL(t *testing.T) {
|
|
got := PublicSubURL("https://panel.example.com/api/", "abc12")
|
|
want := "https://panel.example.com/api/sub/abc12"
|
|
if got != want {
|
|
t.Fatalf("got %q want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestParseInput(t *testing.T) {
|
|
base, short, ok := ParseInput("https://vpn.example.com/api/sub/xyz789/clash")
|
|
if !ok || base != "https://vpn.example.com" || short != "xyz789" {
|
|
t.Fatalf("got base=%q short=%q ok=%v", base, short, ok)
|
|
}
|
|
_, _, ok = ParseInput("https://example.com/not-a-sub")
|
|
if ok {
|
|
t.Fatal("expected not ok")
|
|
}
|
|
}
|
|
|
|
func TestExtractSubscriptionURL(t *testing.T) {
|
|
body := `{"response":{"subscriptionUrl":"https://vpn.example.com/api/sub/abc"}}`
|
|
got := extractSubscriptionURL(body)
|
|
if got != "https://vpn.example.com/api/sub/abc" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|