Files
tenant-registry/internal/server/subroute_test.go
Sharang ParnerkarandClaude Opus 5.5 d31594cc6c
ci / shared (pull_request) Successful in 18s
ci / test (pull_request) Successful in 26m56s
ci / image (pull_request) Skipped
fix(telemetry): name tenant sub-resource requests after their collection
GET /v1/tenants/{id}/{sub} serves eight collections (members, documents,
projects, contracts, managed-services, company-profile, role-dataset,
store), and spans and access-log lines all said '{sub}': SigNoz could
not tell a document-store read from a team list. The route name now
carries the collection when it is one of the eight, and keeps the
wildcard for anything else, so no free path text reaches the name.

The list lives next to the dispatcher; a test keeps the two in step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
2026-10-29 22:28:39 +01:00

46 lines
1.5 KiB
Go

package server
import (
"net/http"
"net/http/httptest"
"slices"
"strings"
"testing"
)
func TestSubRoute(t *testing.T) {
for _, c := range []struct{ path, want string }{
{"/v1/tenants/0b7e/store", "GET /v1/tenants/{id}/store"},
{"/v1/tenants/0b7e/role-dataset", "GET /v1/tenants/{id}/role-dataset"},
{"/v1/tenants/0b7e/members", "GET /v1/tenants/{id}/members"},
{"/v1/tenants/0b7e/typo", tenantSubPattern}, // unknown: no free text in the name
{"/v1/tenants/0b7e/store/x", tenantSubPattern}, // deeper paths are other routes
{"/v1/tenants/0b7e/", tenantSubPattern},
} {
if got := subRoute(c.path); got != c.want {
t.Errorf("subRoute(%q) = %q, want %q", c.path, got, c.want)
}
}
}
// Every name in tenantSubresources reaches a handler; a name the dispatcher
// does not know answers "no such tenant sub-resource". Keeps list and switch
// in step.
func TestTenantSubresourcesMatchDispatcher(t *testing.T) {
s := &Server{}
for _, name := range append(slices.Clone(tenantSubresources), "no-such-thing") {
r := httptest.NewRequest(http.MethodGet, "/v1/tenants/x/"+name, nil)
r.SetPathValue("id", "x")
r.SetPathValue("sub", name)
w := httptest.NewRecorder()
func() {
defer func() { _ = recover() }() // a real handler may need more of Server than this test sets up
s.tenantSubresource(w, r)
}()
unknown := strings.Contains(w.Body.String(), "no such tenant sub-resource")
if want := name == "no-such-thing"; unknown != want {
t.Errorf("%q: dispatcher says unknown=%v", name, unknown)
}
}
}