From 32a15acdea90568dcc91873d4da314f95b14a876 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 12:41:14 +0000 Subject: [PATCH] Add test for CheckShortTerminalWidth with non-string values Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com> --- .../tableprinter/utils/utils_test.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/core/pkg/resultshandling/printer/v2/prettyprinter/tableprinter/utils/utils_test.go b/core/pkg/resultshandling/printer/v2/prettyprinter/tableprinter/utils/utils_test.go index cec7a0a1..90f98020 100644 --- a/core/pkg/resultshandling/printer/v2/prettyprinter/tableprinter/utils/utils_test.go +++ b/core/pkg/resultshandling/printer/v2/prettyprinter/tableprinter/utils/utils_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/jedib0t/go-pretty/v6/table" "github.com/jwalton/gchalk" "github.com/kubescape/opa-utils/reporthandling/apis" "github.com/stretchr/testify/assert" @@ -334,3 +335,69 @@ func TestGetColorForVulnerabilitySeverity(t *testing.T) { }) } } + +func TestCheckShortTerminalWidth(t *testing.T) { +tests := []struct { +name string +rows []table.Row +headers table.Row +// We can't predict the exact result since it depends on terminal size +// but we can test it doesn't panic with various inputs +shouldNotPanic bool +}{ +{ +name: "Normal string rows", +rows: []table.Row{ +{"cell1", "cell2", "cell3"}, +{"longer cell 1", "longer cell 2", "longer cell 3"}, +}, +headers: table.Row{"Header1", "Header2", "Header3"}, +shouldNotPanic: true, +}, +{ +name: "Rows with non-string values (map)", +rows: []table.Row{ +{"cell1", map[string]interface{}{"key": "value"}, "cell3"}, +{"cell4", "cell5", "cell6"}, +}, +headers: table.Row{"Header1", "Header2", "Header3"}, +shouldNotPanic: true, +}, +{ +name: "Headers with non-string values", +rows: []table.Row{ +{"cell1", "cell2", "cell3"}, +}, +headers: table.Row{"Header1", map[string]interface{}{"key": "value"}, "Header3"}, +shouldNotPanic: true, +}, +{ +name: "Both rows and headers with non-string values", +rows: []table.Row{ +{map[string]interface{}{"key": "value"}, "cell2", 123}, +}, +headers: table.Row{[]string{"a", "b"}, "Header2", true}, +shouldNotPanic: true, +}, +{ +name: "Empty rows", +rows: []table.Row{}, +headers: table.Row{"Header1", "Header2"}, +shouldNotPanic: true, +}, +} + +for _, tt := range tests { +t.Run(tt.name, func(t *testing.T) { +defer func() { +if r := recover(); r != nil { +if tt.shouldNotPanic { +t.Errorf("CheckShortTerminalWidth() panicked when it shouldn't: %v", r) +} +} +}() +// Call the function - we just want to ensure it doesn't panic +_ = CheckShortTerminalWidth(tt.rows, tt.headers) +}) +} +}