mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-16 07:54:25 +00:00
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>
This commit is contained in:
@@ -14,24 +14,24 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) {
|
|||||||
handler := &Handler{}
|
handler := &Handler{}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input interface{}
|
input interface{}
|
||||||
expected interface{}
|
shouldBeEmptyArr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "nil should return empty array",
|
name: "nil should return empty array",
|
||||||
input: nil,
|
input: nil,
|
||||||
expected: []interface{}{},
|
shouldBeEmptyArr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty slice should return empty array",
|
name: "empty slice should return empty array",
|
||||||
input: []*EmptyTestModel{},
|
input: []*EmptyTestModel{},
|
||||||
expected: []interface{}{},
|
shouldBeEmptyArr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "single element should return the element",
|
name: "single element should return the element",
|
||||||
input: []*EmptyTestModel{{ID: 1, Name: "test"}},
|
input: []*EmptyTestModel{{ID: 1, Name: "test"}},
|
||||||
expected: &EmptyTestModel{ID: 1, Name: "test"},
|
shouldBeEmptyArr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple elements should return the slice",
|
name: "multiple elements should return the slice",
|
||||||
@@ -39,10 +39,7 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) {
|
|||||||
{ID: 1, Name: "test1"},
|
{ID: 1, Name: "test1"},
|
||||||
{ID: 2, Name: "test2"},
|
{ID: 2, Name: "test2"},
|
||||||
},
|
},
|
||||||
expected: []*EmptyTestModel{
|
shouldBeEmptyArr: false,
|
||||||
{ID: 1, Name: "test1"},
|
|
||||||
{ID: 2, Name: "test2"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +47,8 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
result := handler.normalizeResultArray(tt.input)
|
result := handler.normalizeResultArray(tt.input)
|
||||||
|
|
||||||
// For nil and empty cases, check it returns an empty array
|
// For cases that should return empty array
|
||||||
if tt.input == nil || (tt.name == "empty slice should return empty array") {
|
if tt.shouldBeEmptyArr {
|
||||||
emptyArr, ok := result.([]interface{})
|
emptyArr, ok := result.([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected empty array []interface{}{}, got %T: %v", result, result)
|
t.Errorf("Expected empty array []interface{}{}, got %T: %v", result, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user