Skip to content

Commit 34a656b

Browse files
resolved comments
1 parent 1a11b51 commit 34a656b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

structs/structs.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ func CompareStructs(old, new interface{}) ([]Result, error) {
2424
oldValue := reflect.ValueOf(old)
2525
newValue := reflect.ValueOf(new)
2626

27-
var comparedResults = make([]Result, 0)
27+
if oldValue.Kind() != reflect.Struct || newValue.Kind() != reflect.Struct {
28+
return nil, fmt.Errorf("both parameters should be struct")
29+
}
30+
31+
var comparedResults = make([]Result, 0, oldValue.NumField())
2832

2933
for i := 0; i < oldValue.NumField(); i++ {
3034
field := oldValue.Type().Field(i)

structs/structs_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func TestCompareStructs(t *testing.T) {
7272
},
7373
wantErr: false,
7474
},
75+
{
76+
name: "fail - non struct parameters",
77+
old: map[string]string{"test": "example"},
78+
new: map[string]string{"test": "example-updated"},
79+
want: nil,
80+
wantErr: true,
81+
},
7582
}
7683
for _, tt := range tests {
7784
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)