From 5ad2bd3a78def251e2f145ee032f804fa2a28d1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 14:02:42 +0000 Subject: [PATCH] Improve test robustness - use explicit flag instead of string comparison - Changed test to use shouldBeEmptyArr flag instead of hardcoded name comparison - Makes test more maintainable and less fragile - All tests still passing Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com> --- pkg/restheadspec/empty_result_test.go | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/pkg/restheadspec/empty_result_test.go b/pkg/restheadspec/empty_result_test.go index 31a3ca4..0968d96 100644 --- a/pkg/restheadspec/empty_result_test.go +++ b/pkg/restheadspec/empty_result_test.go @@ -14,24 +14,24 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) { handler := &Handler{} tests := []struct { - name string - input interface{} - expected interface{} + name string + input interface{} + shouldBeEmptyArr bool }{ { - name: "nil should return empty array", - input: nil, - expected: []interface{}{}, + name: "nil should return empty array", + input: nil, + shouldBeEmptyArr: true, }, { - name: "empty slice should return empty array", - input: []*EmptyTestModel{}, - expected: []interface{}{}, + name: "empty slice should return empty array", + input: []*EmptyTestModel{}, + shouldBeEmptyArr: true, }, { - name: "single element should return the element", - input: []*EmptyTestModel{{ID: 1, Name: "test"}}, - expected: &EmptyTestModel{ID: 1, Name: "test"}, + name: "single element should return the element", + input: []*EmptyTestModel{{ID: 1, Name: "test"}}, + shouldBeEmptyArr: false, }, { name: "multiple elements should return the slice", @@ -39,10 +39,7 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) { {ID: 1, Name: "test1"}, {ID: 2, Name: "test2"}, }, - expected: []*EmptyTestModel{ - {ID: 1, Name: "test1"}, - {ID: 2, Name: "test2"}, - }, + shouldBeEmptyArr: false, }, } @@ -50,8 +47,8 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) { t.Run(tt.name, func(t *testing.T) { result := handler.normalizeResultArray(tt.input) - // For nil and empty cases, check it returns an empty array - if tt.input == nil || (tt.name == "empty slice should return empty array") { + // For cases that should return empty array + if tt.shouldBeEmptyArr { emptyArr, ok := result.([]interface{}) if !ok { t.Errorf("Expected empty array []interface{}{}, got %T: %v", result, result)