go-ai/cmd/security/cmd_security_test.go
Virgil cb5342fb1a fix(core): close remaining v0.8.0 compliance gaps
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-27 04:29:11 +00:00

48 lines
1.2 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package security
import (
"strings"
"testing"
)
func TestAlertSummary_PlainString_Good(t *testing.T) {
t.Run("RendersWithoutANSI", func(t *testing.T) {
summary := &AlertSummary{
Critical: 1,
High: 2,
Medium: 3,
Low: 4,
Unknown: 5,
}
got := summary.PlainString()
want := "1 critical | 2 high | 3 medium | 4 low | 5 unknown"
if got != want {
t.Fatalf("PlainString() = %q, want %q", got, want)
}
if strings.Contains(got, "\x1b[") {
t.Fatalf("PlainString() unexpectedly contains ANSI escapes: %q", got)
}
})
t.Run("RendersEmpty", func(t *testing.T) {
summary := &AlertSummary{}
if got := summary.PlainString(); got != "No alerts" {
t.Fatalf("PlainString() = %q, want %q", got, "No alerts")
}
})
}
func TestSecurity_BuildJobIssueBody_Good(t *testing.T) {
summary := &AlertSummary{Critical: 1, High: 2}
body := buildJobIssueBody("owner/repo", summary, []string{"- [HIGH] Finding"})
if strings.Contains(body, "\x1b[") {
t.Fatalf("issue body unexpectedly contains ANSI escapes: %q", body)
}
if !strings.Contains(body, "**Summary:** 1 critical | 2 high") {
t.Fatalf("issue body missing plain summary: %q", body)
}
}