testutil

package
v0.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to v. v is the boolean value to take the address of.

func ForbidExec added in v0.13.0

func ForbidExec(t *testing.T, target *func(string, []string, []string) error)

ForbidExec replaces target with a test failure and restores the original handoff when the test completes.

func SkipIfReadable added in v0.17.2

func SkipIfReadable(t *testing.T, path string)

SkipIfReadable probes path with a real read attempt after a fixture has restricted its mode bits. A successful probe is closed and the test is skipped so elevated privileges cannot bypass a permission-dependent read or traversal error. Permission denied lets the caller proceed. Any other probe error fails with the protected path and the underlying error.

func SkipIfWritable added in v0.17.2

func SkipIfWritable(t *testing.T, path string)

SkipIfWritable probes path with a real write or create attempt after a fixture has restricted its mode bits. A successful probe is cleaned up and the test is skipped so elevated privileges cannot make a permission-dependent assertion pass or fail for an environment reason. Permission denied lets the caller proceed. Any other probe error fails with the protected path and the underlying error.

func WithWorkingDir

func WithWorkingDir(t *testing.T, dir string, fn func())

WithWorkingDir runs fn with dir as the current working directory and restores the previous directory. t is the active test; dir is the temporary working directory for fn.

func WriteStub

func WriteStub(t *testing.T, dir string, name string)

WriteStub writes an executable shell stub that exits successfully. t is the active test; dir is the output directory; name is the executable file name.

func WriteStubWithExit

func WriteStubWithExit(t *testing.T, dir string, name string, exitCode int)

WriteStubWithExit writes an executable shell stub that exits with the provided code. t is the active test; dir is the output directory; name is the executable file name.

Types

type ExecCall added in v0.13.0

type ExecCall struct {
	Called bool
	Path   string
	Argv   []string
	Env    []string
}

ExecCall records one captured executable handoff.

func CaptureExec added in v0.13.0

func CaptureExec(t *testing.T, target *func(string, []string, []string) error, err error) *ExecCall

CaptureExec replaces target with a one-call capture seam that returns err. It restores the original handoff when the test completes.

func (*ExecCall) AssertCalled added in v0.13.0

func (call *ExecCall) AssertCalled(t *testing.T, wantPath string, wantArgv []string)

AssertCalled verifies that the executable handoff occurred once with the expected path and argument vector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL