Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

55 lines
1.6 KiB
Go

package server
import "testing"
func TestCanonicalContractKey(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{"leaves non-http IDs alone", "grpc::user.v1.UserService/GetUser", "grpc::user.v1.UserService/GetUser"},
{"leaves unparameterised routes alone", "http::GET::/v1/health", "http::GET::/v1/health"},
{"rewrites single param", "http::DELETE::/v1/tucks/{id}", "http::DELETE::/v1/tucks/{p1}"},
{
"collapses differing param names to the same key — the exact provider/consumer pairing bug",
"http::DELETE::/v1/workspaces/{wid}/tags/{id}",
"http::DELETE::/v1/workspaces/{p1}/tags/{p2}",
},
{
"consumer variant canonicalises to the same key",
"http::DELETE::/v1/workspaces/{workspaceId}/tags/{id}",
"http::DELETE::/v1/workspaces/{p1}/tags/{p2}",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := canonicalContractKey(tt.in)
if got != tt.want {
t.Errorf("canonicalContractKey(%q) = %q, want %q", tt.in, got, tt.want)
}
})
}
}
func TestContractScope(t *testing.T) {
tests := []struct {
name string
rawType string
producer string
want string
}{
{"go.mod dep always external", "dependency", "core-api", "external"},
{"http with provider is own", "http", "core-api", "own"},
{"http with no provider is external", "http", "", "external"},
{"topic with producer is own", "topic", "worker", "own"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := contractScope(tt.rawType, tt.producer); got != tt.want {
t.Errorf("contractScope(%q, %q) = %q, want %q", tt.rawType, tt.producer, got, tt.want)
}
})
}
}