Skip to content

Commit c68eb95

Browse files
iamleotivan-velasco
authored andcommitted
fix: avoid nil pointer dereference (ovh#615)
Signed-off-by: Leonardo Taccari <[email protected]> Signed-off-by: Ivan Velasco <[email protected]>
1 parent 0395e34 commit c68eb95

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

assertions/assertions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func ShouldContain(actual interface{}, expected ...interface{}) error {
549549
if err := need(1, expected); err != nil {
550550
return err
551551
}
552-
if reflect.TypeOf(actual).Kind() != reflect.Slice {
552+
if actual == nil || reflect.TypeOf(actual).Kind() != reflect.Slice {
553553
return ShouldEqual(actual, expected[0])
554554
}
555555
actualSlice, err := cast.ToSliceE(actual)

assertions/assertions_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,13 @@ func TestShouldContain(t *testing.T) {
666666
},
667667
wantErr: true,
668668
},
669+
{
670+
name: "raise error with nothing",
671+
args: args{
672+
expected: []interface{}{"something"},
673+
},
674+
wantErr: true,
675+
},
669676
}
670677
for _, tt := range tests {
671678
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)