Files
skillshare/internal/audit/policy_test.go
T
Willie ef5a36ce60 feat(audit): change default dedupe mode from legacy to global
Duplicate findings (same pattern+file+line+snippet) are noise.
Global deduplication is now the default for all profiles.
Use --dedupe legacy to opt back into the old behavior.
2026-03-03 16:08:11 +08:00

90 lines
2.6 KiB
Go

package audit
import "testing"
func TestResolvePolicy_Defaults(t *testing.T) {
p := ResolvePolicy(PolicyInputs{})
if p.Profile != ProfileDefault {
t.Errorf("profile = %q, want %q", p.Profile, ProfileDefault)
}
if p.Threshold != SeverityCritical {
t.Errorf("threshold = %q, want %q", p.Threshold, SeverityCritical)
}
if p.DedupeMode != DedupeGlobal {
t.Errorf("dedupe = %q, want %q", p.DedupeMode, DedupeGlobal)
}
}
func TestResolvePolicy_StrictProfile(t *testing.T) {
p := ResolvePolicy(PolicyInputs{Profile: "strict"})
if p.Threshold != SeverityHigh {
t.Errorf("strict threshold = %q, want %q", p.Threshold, SeverityHigh)
}
if p.DedupeMode != DedupeGlobal {
t.Errorf("strict dedupe = %q, want %q", p.DedupeMode, DedupeGlobal)
}
}
func TestResolvePolicy_PermissiveProfile(t *testing.T) {
p := ResolvePolicy(PolicyInputs{Profile: "permissive"})
if p.Threshold != SeverityCritical {
t.Errorf("permissive threshold = %q, want %q", p.Threshold, SeverityCritical)
}
if p.DedupeMode != DedupeLegacy {
t.Errorf("permissive dedupe = %q, want %q", p.DedupeMode, DedupeLegacy)
}
}
func TestResolvePolicy_ExplicitOverridesProfile(t *testing.T) {
p := ResolvePolicy(PolicyInputs{
Profile: "strict",
Threshold: SeverityCritical,
})
if p.Threshold != SeverityCritical {
t.Errorf("explicit threshold = %q, want %q", p.Threshold, SeverityCritical)
}
}
func TestResolvePolicy_ExplicitDedupeOverridesProfile(t *testing.T) {
p := ResolvePolicy(PolicyInputs{
Profile: "strict",
Dedupe: "legacy",
})
if p.DedupeMode != DedupeLegacy {
t.Errorf("explicit dedupe = %q, want %q", p.DedupeMode, DedupeLegacy)
}
}
func TestResolvePolicy_ConfigLayering(t *testing.T) {
p := ResolvePolicy(PolicyInputs{
ConfigThreshold: SeverityHigh,
})
if p.Threshold != SeverityHigh {
t.Errorf("config threshold = %q, want %q", p.Threshold, SeverityHigh)
}
}
func TestResolvePolicy_CLIOverridesConfig(t *testing.T) {
p := ResolvePolicy(PolicyInputs{
ConfigThreshold: SeverityHigh,
Threshold: SeverityMedium,
})
if p.Threshold != SeverityMedium {
t.Errorf("CLI override threshold = %q, want %q", p.Threshold, SeverityMedium)
}
}
func TestResolvePolicy_InvalidProfileFallsBack(t *testing.T) {
p := ResolvePolicy(PolicyInputs{Profile: "bogus"})
if p.Profile != ProfileDefault {
t.Errorf("invalid profile = %q, want %q", p.Profile, ProfileDefault)
}
}
func TestResolvePolicy_InvalidDedupeFallsBack(t *testing.T) {
p := ResolvePolicy(PolicyInputs{Dedupe: "bogus"})
if p.DedupeMode != DedupeLegacy {
t.Errorf("invalid dedupe = %q, want %q", p.DedupeMode, DedupeLegacy)
}
}