testutil

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertDirPath

func AssertDirPath(tb testing.TB, path string, value any)

AssertDirPath asserts the existence of a directory path.

  • If value is true, then the directory SHOULD exist
  • If value is false, then the directory SHOULD NOT exist.

func AssertFilePath

func AssertFilePath(tb testing.TB, path string, value any)

AssertFilePath asserts the existence of a file path.

  • If value is false, then the file SHOULD NOT exist.
  • If value is a string, then the file contents should match.
  • If value is an int, then file permissions should match.

func AssertPaths

func AssertPaths(tb testing.TB, base string, files map[string]any)

AssertPaths asserts each key in files relative to base. Calls AssertDirPath if the key ends in "/", otherwise calls AssertFilePath.

func CurrentDir

func CurrentDir() string

CurrentDir delegates to os.Getwd and panics on error.

func InTempDir

func InTempDir(tb testing.TB, handler func(dir string))

InTempDir runs handler inside a temp dir, then returns back into the cwd.

func MkdirAll

func MkdirAll(tb testing.TB, path string, perm fs.FileMode)

MkdirAll delegates to os.MkdirAll and panics on error. The directory path will be removed when the test exits.

func RemoveAll

func RemoveAll(tb testing.TB, path string)

RemoveAll delegates to os.RemoveAll and panics on error.

func WriteFile

func WriteFile(tb testing.TB, path string, data []byte, perm fs.FileMode)

WriteFile delegates to os.WriteFile and panics on error. The file path will be removed when the test exits.

func WritePaths

func WritePaths(tb testing.TB, base string, files map[string]any)

WritePaths creates a file for each key in files relative to base.

  • The content of the file will be the map value.
  • If the map key ends in a "/", then a directory will be created instead.
  • Any failure to create will panic.
  • All files and directories will be removed when the test exits.

Types

This section is empty.

Jump to

Keyboard shortcuts

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