docs: sync public link configuration reference

This commit is contained in:
A 2026-07-11 20:34:10 +08:00
parent 4390ebf5a9
commit c0088f1160
13 changed files with 857 additions and 100 deletions

View file

@ -2,6 +2,7 @@ package links
import (
"net/url"
"strings"
"testing"
)
@ -59,6 +60,45 @@ func TestValidateBaseURL(t *testing.T) {
}
}
func TestValidateAppScheme(t *testing.T) {
tests := []struct {
name string
raw string
want string
wantErr bool
}{
{name: "default", raw: "", want: "telesrv"},
{name: "normalized", raw: " My-App+Dev ", want: "my-app+dev"},
{name: "starts with digit", raw: "1app", wantErr: true},
{name: "colon", raw: "myapp:", wantErr: true},
{name: "official tg", raw: "tg", wantErr: true},
{name: "http", raw: "http", wantErr: true},
{name: "https", raw: "https", wantErr: true},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got, err := ValidateAppScheme(tc.raw)
if (err != nil) != tc.wantErr {
t.Fatalf("ValidateAppScheme(%q) error = %v, wantErr %v", tc.raw, err, tc.wantErr)
}
if got != tc.want {
t.Fatalf("ValidateAppScheme(%q) = %q, want %q", tc.raw, got, tc.want)
}
})
}
}
func TestValidateAppName(t *testing.T) {
if got, err := ValidateAppName(" Example Chat "); err != nil || got != "Example Chat" {
t.Fatalf("ValidateAppName valid = %q, %v", got, err)
}
for _, raw := range []string{"", " ", "bad\nname", strings.Repeat("x", 65)} {
if got, err := ValidateAppName(raw); err == nil {
t.Fatalf("ValidateAppName(%q) = %q, want error", raw, got)
}
}
}
func TestBuildPreservesBasePathAndQuery(t *testing.T) {
got := Build("http://127.0.0.1:2401/root/", "/call/abc", url.Values{"slug": []string{"abc"}})
if want := "http://127.0.0.1:2401/root/call/abc?slug=abc"; got != want {