Skip to content

fix: formatLimitedList only tested with ten elements; missing edge - #202

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:tests/addressing-test-formatlimitedlist-only-tested-with-ten
Open

fix: formatLimitedList only tested with ten elements; missing edge#202
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:tests/addressing-test-formatlimitedlist-only-tested-with-ten

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in pkg/networkoperatorplugin/spectrumx/addressing_test.go: formatLimitedList only tested with ten elements; missing edge.

Changes

  • pkg/networkoperatorplugin/spectrumx/addressing_test.go: formatLimitedList only tested with ten elements; missing edge.

Details

--- a/pkg/networkoperatorplugin/spectrumx/addressing_test.go
+++ b/pkg/networkoperatorplugin/spectrumx/addressing_test.go
@@ -1,7 +1,39 @@
-func TestFormatLimitedList(t *testing.T) {
-	values := []string{"node-09", "node-03", "node-01", "node-07", "node-05", "node-10", "node-08", "node-02", "node-06", "node-04"}
-
-	require.Equal(t,
-		"[node-01, node-02, node-03, node-04, node-05, node-06, node-07, node-08] (+2 more)",
-		formatLimitedList(values))
-}
+func TestFormatLimitedList(t *testing.T) {
+	tests := []struct {
+		name   string
+		values []string
+		want   string
+	}{
+		{
+			name:   "empty",
+			values: []string{},
+			want:   "[]",
+		},
+		{
+			name:   "single value",
+			values: []string{"node-z"},
+			want:   "[node-z]",
+		},
+		{
+			name:   "exactly limit",
+			values: []string{"node-09", "node-03", "node-01", "node-07", "node-05", "node-08", "node-02", "node-06"},
+			want:   "[node-01, node-02, node-03, node-05, node-06, node-07, node-08, node-09]",
+		},
+		{
+			name:   "above limit",
+			values: []string{"node-09", "node-03", "node-01", "node-07", "node-05", "node-10", "node-08", "node-02", "node-06", "node-04"},
+			want:   "[node-01, node-02, node-03, node-04, node-05, node-06, node-07, node-08] (+2 more)",
+		},
+		{
+			name:   "lexicographic not numeric sort",
+			values: []string{"node-10", "node-2"},
+			want:   "[node-10, node-2]",
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			require.Equal(t, tt.want, formatLimitedList(tt.values))
+		})
+	}
+}

Tests

  • pkg/networkoperatorplugin/spectrumx/addressing_test.go
--- pkg/networkoperatorplugin/spectrumx/addressing_test.go
+++ pkg/networkoperatorplugin/spectrumx/addressing_test.go
@@ -330,11 +330,38 @@
 func TestFormatLimitedList(t *testing.T) {
-	values := []string{"node-09", "node-03", "node-01", "node-07", "node-05", "node-10", "node-08", "node-02", "node-06", "node-04"}
-
-	require.Equal(t,
-		"[node-01, node-02, node-03, node-04, node-05, node-06, node-07, node-08] (+2 more)",
-		formatLimitedList(values))
+	tests := []struct {
+		name   string
+		values []string
+		want   string
+	}{
+		{
+			name:   "empty",
+			values: []string{},
+			want:   "[]",
+		},
+		{
+			name:   "single value",
+			values: []string{"node-z"},
+			want:   "[node-z]",
+		},
+		{
+			name:   "exactly limit",
+			values: []string{"node-09", "node-03", "node-01", "node-07", "node-05", "node-08", "node-02", "node-06"},
+			want:   "[node-01, node-02, node-03, node-05, node-06, node-07, node-08, node-09]",
+		},
+		{
+			name:   "above limit",
+			values: []string{"node-09", "node-03", "node-01", "node-07", "node-05", "node-10", "node-08", "node-02", "node-06", "node-04"},
+			want:   "[node-01, node-02, node-03, node-04, node-05, node-06, node-07, node-08] (+2 more)",
+		},
+		{
+			name:   "lexicographic not numeric sort",
+			values: []string{"node-10", "node-2"},
+			want:   "[node-10, node-2]",
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			require.Equal(t, tt.want, formatLimitedList(tt.values))
+		})
+	}
 }

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR expands formatLimitedList unit-test coverage with table-driven cases for empty, single-item, exact-limit, above-limit, and lexicographic-order inputs.

  • Preserves the existing above-limit assertion.
  • Adds coverage for the previously untested limit boundary and smaller inputs.

Confidence Score: 5/5

The PR appears safe to merge because it only broadens unit-test coverage with consistent expected results.

The changed test cases exercise additional input sizes and sorting behavior without modifying runtime code or introducing a test expectation that conflicts with the formatter’s established contract.

Important Files Changed

Filename Overview
pkg/networkoperatorplugin/spectrumx/addressing_test.go Converts the formatter test to table-driven coverage without changing production behavior; no actionable issues found.

Reviews (1): Last reviewed commit: "fix: formatLimitedList only tested with ..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant