Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package web
|
|
|
|
import "testing"
|
|
|
|
func TestRouteURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
pattern string
|
|
args []any
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no placeholders",
|
|
pattern: "/partials/operator/products",
|
|
want: "/partials/operator/products",
|
|
},
|
|
{
|
|
name: "single placeholder",
|
|
pattern: "/partials/operator/products/{productID}",
|
|
args: []any{42},
|
|
want: "/partials/operator/products/42",
|
|
},
|
|
{
|
|
name: "two placeholders",
|
|
pattern: "/partials/operator/organizations/{orgID}/pools/{poolID}/grant",
|
|
args: []any{"org-abc", "pool-xyz"},
|
|
want: "/partials/operator/organizations/org-abc/pools/pool-xyz/grant",
|
|
},
|
|
{
|
|
name: "value needs path escape",
|
|
pattern: "/partials/operator/org-types/{orgType}/default-plan",
|
|
args: []any{"co-op/personal"},
|
|
want: "/partials/operator/org-types/co-op%2Fpersonal/default-plan",
|
|
},
|
|
{
|
|
name: "trailing wildcard placeholder treated like normal",
|
|
pattern: "/foo/{rest...}",
|
|
args: []any{"a/b"},
|
|
want: "/foo/a%2Fb",
|
|
},
|
|
{
|
|
name: "too few args",
|
|
pattern: "/foo/{a}/bar/{b}",
|
|
args: []any{"x"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "too many args",
|
|
pattern: "/foo/{a}",
|
|
args: []any{"x", "y"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "unclosed placeholder",
|
|
pattern: "/foo/{a",
|
|
args: []any{"x"},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := RouteURL(tt.pattern, tt.args...)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("RouteURL() err=%v wantErr=%v", err, tt.wantErr)
|
|
}
|
|
if !tt.wantErr && got != tt.want {
|
|
t.Errorf("RouteURL() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|