Files
pulse/internal/api/license_limits_test_helpers_test.go
rcourtman 81b31e4d3b Remove monitored-system volume caps
Retire runtime/API/UI monitored-system volume enforcement now that infrastructure monitoring is no longer capped.

Keep only legacy metadata scrubbing and purchase-start compatibility for old max_monitored_systems references.

Rename the remaining preview surface to monitored-system impact and make previews explanatory rather than save-blocking.

Update subsystem contracts and RA7 evidence for the caps-retired invariant.
2026-05-05 12:59:59 +01:00

72 lines
1.8 KiB
Go

package api
import (
"context"
"sync"
"testing"
"time"
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
licensetestsupport "github.com/rcourtman/pulse-go-rewrite/pkg/licensing/testsupport"
)
type staticLicenseProvider struct {
service *pkglicensing.Service
}
var testLicenseProviderMu sync.Mutex
func (p *staticLicenseProvider) Service(context.Context) *pkglicensing.Service {
return p.service
}
func setMaxMonitoredSystemsLicenseForTests(t *testing.T, maxMonitoredSystems int) {
t.Helper()
_ = maxMonitoredSystems
testLicenseProviderMu.Lock()
t.Setenv("PULSE_LICENSE_DEV_MODE", "true")
service := pkglicensing.NewService()
licenseKey, err := licensetestsupport.GenerateLicenseForTesting("limits@example.com", pkglicensing.TierEnterprise, 24*time.Hour)
if err != nil {
t.Fatalf("failed to generate test license: %v", err)
}
if _, err := service.Activate(licenseKey); err != nil {
t.Fatalf("failed to activate test license: %v", err)
}
SetLicenseServiceProvider(&staticLicenseProvider{service: service})
t.Cleanup(func() {
SetLicenseServiceProvider(nil)
testLicenseProviderMu.Unlock()
})
}
func setLicenseTierForHandlersForTests(t *testing.T, handlers *LicenseHandlers, orgID string, tier pkglicensing.Tier) {
t.Helper()
if handlers == nil {
t.Fatal("license handlers are required")
}
ctx := context.Background()
if orgID != "" {
ctx = context.WithValue(ctx, OrgIDContextKey, orgID)
}
svc := handlers.Service(ctx)
if svc == nil {
t.Fatal("license service is required")
}
svc.SetCurrentForTesting(&pkglicensing.License{
Claims: pkglicensing.Claims{
LicenseID: "api-route-license-tier-test",
Email: "route-license@example.test",
Tier: tier,
IssuedAt: time.Now().Add(-time.Hour).Unix(),
ExpiresAt: time.Now().Add(24 * time.Hour).Unix(),
},
ValidatedAt: time.Now(),
})
}