-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathlicenses_test.go
More file actions
50 lines (42 loc) · 2.15 KB
/
Copy pathlicenses_test.go
File metadata and controls
50 lines (42 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package codersdk_test
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/codersdk"
)
// TestLicenseAgentRuntimeHoursWarningTexts pins the warning-text prefix
// couplings consumed by the dashboard's LicenseBanner
// (site/src/modules/dashboard/LicenseBanner).
func TestLicenseAgentRuntimeHoursWarningTexts(t *testing.T) {
t.Parallel()
// Cut rather than Split so a template losing its placeholder fails the
// test instead of silently turning the whole message into the "prefix".
templatePrefix := func(text, placeholder string) string {
t.Helper()
prefix, _, ok := strings.Cut(text, placeholder)
require.True(t, ok, "template %q must contain placeholder %q", text, placeholder)
return prefix
}
aiGovNearLimitPrefix := templatePrefix(codersdk.LicenseAIGovernance90PercentWarningText, "%d%%")
aiGovOverLimitPrefix := templatePrefix(codersdk.LicenseAIGovernanceOverLimitWarningText, "%d")
softLimitPrefix := templatePrefix(codersdk.LicenseAgentRuntimeHoursSoftLimitWarningText, "%d")
runtimeTexts := map[string]string{
"SoftLimit": codersdk.LicenseAgentRuntimeHoursSoftLimitWarningText,
"AllocationReached": codersdk.LicenseAgentRuntimeHoursAllocationReachedWarningText,
}
for name, text := range runtimeTexts {
// isMutedWarning renders near-limit matches muted, and
// isAIGovernanceWarning matches either AI Governance prefix to
// suppress the banner's client-side over-limit fallback.
require.False(t, strings.HasPrefix(text, aiGovNearLimitPrefix),
"%s warning must not share the AI Governance near-limit prefix %q", name, aiGovNearLimitPrefix)
require.False(t, strings.HasPrefix(text, aiGovOverLimitPrefix),
"%s warning must not share the AI Governance over-limit prefix %q", name, aiGovOverLimitPrefix)
}
// isMutedWarning renders soft-limit matches muted and messageLink drops
// their sales link, so the allocation-reached warning must not match.
allocationReachedText := codersdk.LicenseAgentRuntimeHoursAllocationReachedWarningText
require.False(t, strings.HasPrefix(allocationReachedText, softLimitPrefix),
"the soft-limit prefix must not classify the allocation-reached warning")
}