mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 15:46:37 +08:00
feat(core): add HandleRaw and BasePath for trailing-slash routes
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package extpoints
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHandleRawPreservesTrailingSlash(t *testing.T) {
|
||||
r := &RouterRegistry{}
|
||||
g := r.Group("/api/v1/nodes")
|
||||
|
||||
if got := g.BasePath(); got != "/api/v1/nodes" {
|
||||
t.Fatalf("BasePath() = %q, want %q", got, "/api/v1/nodes")
|
||||
}
|
||||
slashless := g.Handle("GET", "")
|
||||
slashed := g.HandleRaw("GET", "/")
|
||||
|
||||
if slashless.Path != "/api/v1/nodes" {
|
||||
t.Errorf("Handle(\"\") path = %q, want %q", slashless.Path, "/api/v1/nodes")
|
||||
}
|
||||
if slashed.Path != "/api/v1/nodes/" {
|
||||
t.Errorf("HandleRaw(\"/\") path = %q, want %q", slashed.Path, "/api/v1/nodes/")
|
||||
}
|
||||
if slashed.ID == slashless.ID {
|
||||
t.Error("HandleRaw must allocate its own route ID")
|
||||
}
|
||||
if got := len(r.Routes()); got != 2 {
|
||||
t.Errorf("registry routes = %d, want 2", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user