mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-12 17:04:21 +00:00
27c9415193
Add automated coverage floor validation: - scripts/check_coverage.go: parses coverage.out, compares to per-package thresholds, supports --update to lock current floors - scripts/coverage_thresholds.json: 61 packages, initial floors from Phase 1 - .github/workflows/ci.yaml: new 'Coverage ratchet gate' step in CI - internal/testutil/: test utilities (context builders, TestDB, doc.go)
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
)
|
|
|
|
// TenantCtx returns a context seeded with the given tenant UUID.
|
|
// Panics on malformed uuid strings to keep test call-sites concise.
|
|
func TenantCtx(tenantID uuid.UUID) context.Context {
|
|
return store.WithTenantID(context.Background(), tenantID)
|
|
}
|
|
|
|
// UserCtx returns a context with tenant + user identities set.
|
|
func UserCtx(tenantID uuid.UUID, userID string) context.Context {
|
|
ctx := store.WithTenantID(context.Background(), tenantID)
|
|
return store.WithUserID(ctx, userID)
|
|
}
|
|
|
|
// AgentCtx returns a context with tenant + agent identities set.
|
|
func AgentCtx(tenantID, agentID uuid.UUID) context.Context {
|
|
ctx := store.WithTenantID(context.Background(), tenantID)
|
|
return store.WithAgentID(ctx, agentID)
|
|
}
|
|
|
|
// FullCtx returns a context with tenant + user + agent identities set.
|
|
func FullCtx(tenantID uuid.UUID, userID string, agentID uuid.UUID) context.Context {
|
|
ctx := store.WithTenantID(context.Background(), tenantID)
|
|
ctx = store.WithUserID(ctx, userID)
|
|
return store.WithAgentID(ctx, agentID)
|
|
}
|
|
|
|
// MustParseUUID is a helper for tests to turn a literal into uuid.UUID.
|
|
// Tests die loudly on malformed input; production code should never touch this.
|
|
func MustParseUUID(s string) uuid.UUID {
|
|
id, err := uuid.Parse(s)
|
|
if err != nil {
|
|
panic("testutil.MustParseUUID: " + err.Error())
|
|
}
|
|
return id
|
|
}
|