Skip to content

Commit 981518b

Browse files
committed
testutils: add Contains, to check if an interface value contains a given type
Signed-off-by: Timo Beckers <[email protected]>
1 parent b6120ca commit 981518b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/testutils/checkers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import (
88
"github.com/go-quicktest/qt"
99
)
1010

11+
// Contains checks if interface value I is of type T. Use with qt.Satisfies:
12+
//
13+
// qt.Assert(t, qt.Satisfies(p, testutils.Contains[*ebpf.Program]))
14+
func Contains[T, I any](i I) bool {
15+
_, ok := any(i).(T)
16+
return ok
17+
}
18+
1119
// IsDeepCopy checks that got is a deep copy of want.
1220
//
1321
// All primitive values must be equal, but pointers must be distinct.

0 commit comments

Comments
 (0)