Skip to content

Commit 522ac74

Browse files
pillai-ashwinjulianwiedmann
authored andcommitted
pkg/hubble/filters: replace reflect.DeepEqual with assert.Equal in tests
Replace all uses of reflect.DeepEqual with assert.Equal from the github.com/stretchr/testify/assert package in pkg/hubble/filters/ test files. This provides better error messages when test assertions fail by showing which specific fields differ between expected and actual values. Fixes: cilium#40562 Signed-off-by: Ashwin Pillai <pillaiashwin96@gmail.com>
1 parent 90a5894 commit 522ac74

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

pkg/hubble/filters/labelparser_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
package filters
55

66
import (
7-
"reflect"
87
"testing"
8+
9+
"github.com/stretchr/testify/assert"
910
)
1011

1112
func Test_translateSelector(t *testing.T) {
@@ -93,8 +94,8 @@ func Test_translateSelector(t *testing.T) {
9394
t.Errorf("parseSelector() error = %v, wantErr %v", err, tt.wantErr)
9495
return
9596
}
96-
if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {
97-
t.Errorf("parseSelector() = %q, want %q", got, tt.want)
97+
if !tt.wantErr {
98+
assert.Equal(t, tt.want, got)
9899
}
99100
})
100101
}

pkg/hubble/filters/labels_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
package filters
55

66
import (
7-
"reflect"
87
"testing"
98

9+
"github.com/stretchr/testify/assert"
10+
1011
flowpb "github.com/cilium/cilium/api/v1/flow"
1112
v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
1213
)
@@ -647,8 +648,8 @@ func Test_parseSelector(t *testing.T) {
647648
t.Errorf("parseSelector() error = %v, wantErr %v", err, tt.wantErr)
648649
return
649650
}
650-
if !tt.wantErr && !reflect.DeepEqual(got.String(), tt.want) {
651-
t.Errorf("parseSelector() = %q, want %q", got, tt.want)
651+
if !tt.wantErr {
652+
assert.Equal(t, tt.want, got.String())
652653
}
653654
})
654655
}

0 commit comments

Comments
 (0)