Documentation
¶
Overview ¶
Package testutils provides some internal helpers for tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MkdirAll = testutils.MkdirAll
MkdirAll is a wrapper around os.MkdirAll.
var Symlink = testutils.Symlink
Symlink is a wrapper around os.Symlink.
var WriteFile = testutils.WriteFile
WriteFile is a wrapper around os.WriteFile.
Functions ¶
func CreateInTree ¶
CreateInTree creates a given inode inside the root directory.
Format:
dir <name> <?uid:gid:mode> file <name> <?content> <?uid:gid:mode> symlink <name> <target> char <name> <major> <minor> <?uid:gid:mode> block <name> <major> <minor> <?uid:gid:mode> fifo <name> <?uid:gid:mode> sock <name> <?uid:gid:mode>
func CreateTree ¶
CreateTree creates a rootfs tree using spec entries (as documented in CreateInTree). The returned path is the path to the root of the new tree.
func RequireRenameExchange ¶
func RequireRenameExchange(t TestingT)
RequireRenameExchange skips the current test if renameat2(2) is not supported on the running system.
func RequireRoot ¶
func RequireRoot(t TestingT)
RequireRoot skips the current test if we are not root.
func WithWithoutOpenat2 ¶
WithWithoutOpenat2 runs a given test with and without openat2 (by forcefully disabling its usage).
Types ¶
type TDoFunc ¶
type TDoFunc func(ti TestingT)
TDoFunc is effectively a func(t *testing.T) function but using the TestingT interface to allow us to write testutils with non-test code. The argument is virtually guaranteed to be a *testing.T instance so you can just do a type assertion in the body of the closure.
type TRunFunc ¶
TRunFunc is a wrapper around t.Run but done with an interface that can be used in non-testing code. To use this, you should just define a wrapper function like this:
func tRunWrapper(t *testing.T) testutils.TRunFunc {
return func(name string, doFn testutils.TDoFunc) {
t.Run(name, func(t *testing.T) {
doFn(t)
})
}
}
and then use it with WithWithoutOpenat2 like so:
testutils.WithWithoutOpenat2(true, tRunWrapper(t), func(ti testutils.TestingT) {
t := ti.(*testing.T) //nolint:forcetypeassert // guaranteed to be true and in test code
/* test code */
})