Files
goclaw/internal/testutil/context.go
T
viettranx 27c9415193 build(ci): add coverage ratchet gate with per-package floors
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)
2026-04-11 21:22:23 +07:00

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
}