Pulse/internal/api/websocket_isolation_test.go
rcourtman faefe6edc8 Remove 198 unreachable Go functions
Dead-code sweep. Functions flagged unreachable by golang.org/x/tools/cmd/deadcode
and confirmed unused across pulse, pulse-enterprise, pulse-pro and pulse-mobile by
adversarial cross-repo verification. Cross-module reachability was checked
explicitly (only pkg/ exported symbols are importable by other modules; internal/
packages and _test.go files are not). go build, go vet and test-compile all pass.
2026-06-03 12:29:37 +01:00

48 lines
1.5 KiB
Go

package api
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
// WSMockLicenseService for checking feature flags in tests
type WSMockLicenseService struct {
Features map[string]bool
}
// WebSocketMockLicenseProvider to return our mock service
type WebSocketMockLicenseProvider struct {
service *WSMockLicenseService
}
func TestWebSocketIsolation_Permanent(t *testing.T) {
// Reset global state
defer SetMultiTenantEnabled(false)
checker := NewMultiTenantChecker(false) // self-hosted mode for existing tests
// Case 1: Default Org always allowed
result := checker.CheckMultiTenant(context.Background(), "default")
assert.True(t, result.Allowed)
assert.True(t, result.FeatureEnabled)
assert.True(t, result.Licensed)
// Case 2: Multi-Tenant Disabled (Flag=False)
SetMultiTenantEnabled(false)
result = checker.CheckMultiTenant(context.Background(), "tenant-1")
assert.False(t, result.Allowed)
assert.False(t, result.FeatureEnabled, "Feature should be disabled")
assert.Contains(t, result.Reason, "not enabled")
// Case 3: Flag=True, License=False
SetMultiTenantEnabled(true)
// Default license provider returns no license, which is what we want to test (Block unlicensed)
result = checker.CheckMultiTenant(context.Background(), "tenant-1")
assert.False(t, result.Allowed)
assert.True(t, result.FeatureEnabled)
assert.False(t, result.Licensed, "Should be unlicensed by default")
assert.Contains(t, result.Reason, "Enterprise license")
}