testutil

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureStdout

func CaptureStdout(t testing.TB, fn func()) string

CaptureStdout redirects os.Stdout during fn and returns all captured output.

Reading from the pipe runs in a separate goroutine concurrently with fn(), avoiding deadlock when output exceeds the pipe buffer size (~64KB on Linux).

Incompatible with t.Parallel() due to mutation of the global os.Stdout.

func CreateTestTAR

func CreateTestTAR(t *testing.T, files map[string]string) string

CreateTestTAR creates a plain .tar file from a name-to-content map.

func CreateTestTARBzip2

func CreateTestTARBzip2(t *testing.T, files map[string]string) string

CreateTestTARBzip2 creates a .tar.bz2 file.

compress/bzip2 in Go stdlib has no Writer, so the system bzip2 utility is used via os/exec. If bzip2 is not available the test is skipped.

The intermediate .tar file is removed after compression.

func CreateTestTARGzip

func CreateTestTARGzip(t *testing.T, files map[string]string) string

CreateTestTARGzip creates a .tar.gz file.

func CreateTestTARWithSymlink(t *testing.T, linkTarget string) string

CreateTestTARWithSymlink creates a plain .tar with a symlink entry pointing to the given target. Also includes an ordinary readme.txt to verify mixed content.

func CreateTestZIP

func CreateTestZIP(t *testing.T, files map[string]string) string

CreateTestZIP creates a ZIP file from a name-to-content map. Returns the file path.

func CreateTestZIPWithCompressionRatio

func CreateTestZIPWithCompressionRatio(t *testing.T) string

CreateTestZIPWithCompressionRatio creates a ZIP with a highly compressible entry (1 MB of zeros) that Deflate compresses to ~1 KB, for testing the zip_bomb detection rule.

func CreateTestZIPWithSymlink(t *testing.T) string

CreateTestZIPWithSymlink creates a ZIP file containing a symlink entry.

func WithArgs

func WithArgs(t testing.TB, progName string, args []string, fn func())

WithArgs temporarily replaces os.Args with [progName, args...], calls fn, then restores the original value.

progName is set as the program name (os.Args[0]). The value does not need to match the real binary name — tests may pass any value.

Incompatible with t.Parallel() due to mutation of the global os.Args.

Types

This section is empty.

Jump to

Keyboard shortcuts

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