Skip to content

Commit 1ecda49

Browse files
alexpantyukhingeorgelesica-wf
authored andcommitted
fix for comparing kinds
1 parent f1df803 commit 1ecda49

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

assert/assertions.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,17 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
419419
return Fail(t, "Expected value not to be nil.", msgAndArgs...)
420420
}
421421

422+
// containsKind checks if a specified kind in the slice of kinds.
423+
func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool {
424+
for i := 0; i < len(kinds); i++ {
425+
if kind == kinds[i] {
426+
return true
427+
}
428+
}
429+
430+
return false
431+
}
432+
422433
// isNil checks if a specified object is nil or not, without Failing.
423434
func isNil(object interface{}) bool {
424435
if object == nil {
@@ -427,7 +438,14 @@ func isNil(object interface{}) bool {
427438

428439
value := reflect.ValueOf(object)
429440
kind := value.Kind()
430-
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
441+
isNilableKind := containsKind(
442+
[]reflect.Kind{
443+
reflect.Chan, reflect.Func,
444+
reflect.Interface, reflect.Map,
445+
reflect.Ptr, reflect.Slice},
446+
kind)
447+
448+
if isNilableKind && value.IsNil() {
431449
return true
432450
}
433451

0 commit comments

Comments
 (0)