osutil

package
v0.0.0-...-7426b64 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureStderr

func CaptureStderr(fnToExec func()) (string, error)

CaptureStderr will execute a provided function and capture anything written to stderr. It will then return that output as a string along with any errors captured in the process.

func CaptureStdout

func CaptureStdout(fnToExec func()) (string, error)

CaptureStdout will execute a provided function and capture anything written to stdout. It will then return that output as a string along with any errors captured in the process.

func CopyTestFileToConfigDir

func CopyTestFileToConfigDir(configPath, testFileName, targetFileName string, targetFileMode os.FileMode) error

CopyTestFileToConfigDir copies a file in a relatve `testdata` dir to the caller of this function to the config dir as some target filename with some target FileMode.

func CreateConfigFile

func CreateConfigFile(configPath string, fileName string, fileMode os.FileMode) (*os.File, error)

CreateConfigFile will create a file in the config dir with the given file name.

func GetTestDataDir

func GetTestDataDir() string

GetTestDataDir returns the path to the caller's `testdata` directory.

func GetTestFile

func GetTestFile(fileName ...string) string

GetTestFile returns the path to the given fileName in the calling function's `testdata` directory.

func PrepareDir

func PrepareDir(path string) string

PrepareDir prepares a path for use in tests (ensures it exists and ensures the path is concistent)

func ReadConfigFile

func ReadConfigFile(configPath, fileName string) (string, error)

ReadConfigFile will read the contents of a file in the config dir.

func ReadTestFile

func ReadTestFile(fileName string) (string, error)

ReadTestFile will read the contents of a file from the `testdata` directory relative to the path of the calling function file. This function assumes it is called directly from a function in a file in the directory the `testdata` exists in.

func RemoveConfigFile

func RemoveConfigFile(configPath, fileName string) error

RemoveConfigFile will remove a file from the config dir with the given file name.

func StatConfigFile

func StatConfigFile(configPath, fileName string) (os.FileInfo, error)

StatConfigFile returns the os.FileInfo for a file in the config dir.

func WrapStdin

func WrapStdin(fnToExec func(), inputLines ...interface{})

WrapStdin will fill stdin with the lines provided as a variadic list of strings before executing the provided function. Each line will be appended with a newline (\n) only.

func WrapStdinWithDelay

func WrapStdinWithDelay(delay time.Duration, fnToExec func(), inputLines ...interface{})

WrapStdinWithDelay will fill stdin with the lines provided, but with a given delay before each write. This is useful if there is a reader that reads all of stdin between prompts, for instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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