Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ func renderRecommendationListText(recommendations []map[string]any) []byte {

grouped := groupRecommendations(recommendations)
rows := make([][]string, 0, len(grouped)+1)
rows = append(rows, []string{"KIND", "CONTAINER", "NAME", "NAMESPACE", "CPU REQUESTS", "CPU LIMITS", "MEMORY REQUESTS", "MEMORY LIMITS"})
rows = append(rows, []string{"KIND", "NAMESPACE", "NAME", "CONTAINER", "CPU REQUESTS", "CPU LIMITS", "MEMORY REQUESTS", "MEMORY LIMITS"})

for _, recommendation := range grouped {
rows = append(rows, []string{
recommendation.kind,
recommendation.container,
recommendation.name,
recommendation.namespace,
recommendation.name,
recommendation.container,
recommendation.cpuRequests,
recommendation.cpuLimits,
recommendation.memoryRequests,
Expand Down
45 changes: 34 additions & 11 deletions internal/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ import (
"testing"
)

func assertHeaderOrder(t *testing.T, output string, expected []string) {
t.Helper()

lines := strings.Split(strings.TrimRight(output, "\n"), "\n")
if len(lines) == 0 {
t.Fatalf("expected header line in output %q", output)
}

header := lines[0]
start := 0
for _, column := range expected {
index := strings.Index(header[start:], column)
if index == -1 {
t.Fatalf("expected header %q in line %q", column, header)
}
start += index + len(column)
}
}

func TestWriteTextClusterList(t *testing.T) {
var out bytes.Buffer
value := []map[string]any{
Expand Down Expand Up @@ -235,9 +254,9 @@ func TestWriteTextRecommendationsListUsesTable(t *testing.T) {
got := out.String()
for _, expected := range []string{
"KIND",
"CONTAINER",
"NAME",
"NAMESPACE",
"NAME",
"CONTAINER",
Comment thread
josefkarasek marked this conversation as resolved.
"CPU REQUESTS",
"CPU LIMITS",
"MEMORY REQUESTS",
Expand All @@ -253,9 +272,7 @@ func TestWriteTextRecommendationsListUsesTable(t *testing.T) {
t.Fatalf("expected %q in output %q", expected, got)
}
}
if !strings.Contains(got, "KIND") || !strings.Contains(got, "CONTAINER") || !strings.Contains(got, "MEMORY LIMITS") {
t.Fatalf("unexpected header order in output %q", got)
}
assertHeaderOrder(t, got, []string{"KIND", "NAMESPACE", "NAME", "CONTAINER", "CPU REQUESTS", "CPU LIMITS", "MEMORY REQUESTS", "MEMORY LIMITS"})
if strings.Contains(got, "AGENT VERSION") {
t.Fatalf("unexpected cluster table output: %q", got)
}
Expand Down Expand Up @@ -289,9 +306,9 @@ func TestWriteTextRecommendationsFromSampleFileUsesTable(t *testing.T) {
got := out.String()
for _, expected := range []string{
"KIND",
"CONTAINER",
"NAME",
"NAMESPACE",
"NAME",
"CONTAINER",
"CPU REQUESTS",
"CPU LIMITS",
"MEMORY REQUESTS",
Expand All @@ -318,11 +335,17 @@ func TestWriteTextRecommendationsFromSampleFileUsesTable(t *testing.T) {
if !strings.Contains(got, "audit-sidecar") || !strings.Contains(got, "16Mi -> 24Mi") || !strings.Contains(got, "64Mi -> 72Mi") {
t.Fatalf("expected sidecar recommendation row in output %q", got)
}
if !strings.Contains(got, "NAME") || !strings.Contains(got, "CONTAINER") || !strings.Contains(got, "MEMORY LIMITS") {
t.Fatalf("missing recommendation headers in output %q", got)
assertHeaderOrder(t, got, []string{"KIND", "NAMESPACE", "NAME", "CONTAINER", "CPU REQUESTS", "CPU LIMITS", "MEMORY REQUESTS", "MEMORY LIMITS"})
found := false
for _, line := range strings.Split(got, "\n") {
fields := strings.Fields(line)
if len(fields) >= 4 && fields[0] == "Deployment" && fields[1] == "keda" && fields[2] == "kedify-agent" && fields[3] == "manager" {
found = true
break
}
}
if !strings.Contains(got, "Deployment manager") {
t.Fatalf("expected workload container column in output %q", got)
if !found {
t.Fatalf("expected workload row with container column in output %q", got)
}
}

Expand Down
Loading