util

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(
	dir string,
	data interface{},
	deleteSources bool,
	strict bool,
) error

ApplyTemplate runs golang templating on all files in the provided path, replacing them in-place with their templated versions.

func CloneRepo

func CloneRepo(ctx context.Context, url string, ref string, path string) error

CloneRepo makes a shallow clone of the argument repo at a single ref.

See https://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset for a discussion of the commands run.

func CompareJSONObjs

func CompareJSONObjs(t *testing.T, exp kruntime.Object, actual kruntime.Object)

CompareJSONObjs compares two objects via their JSON representations. This is much easier to debug that comparing the objects directly.

func Confirm

func Confirm(ctx context.Context, prompt string, skip bool) (bool, error)

Confirm gets a yes/no confirmation from the user on the command-line before continuing.

func DirExists

func DirExists(path string) (bool, error)

DirExists returns whether the given path exists and is a directory.

func FileExists

func FileExists(path string) (bool, error)

FileExists returns whether the given path exists and is a file.

func GetContents

func GetContents(t *testing.T, root string) map[string][]string

GetContents returns the contents of a directory as a map from file name to string content lines.

func GetFileContents

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

GetFileContents gets the string contents of a single file.

func RecursiveCopy

func RecursiveCopy(srcDir string, destDir string) error

RecursiveCopy does a recursive copy from the source directory to the destination one.

func RemoveDirs

func RemoveDirs(rootDir string, indicatorName string) error

RemoveDirs removes all directories that contain a file with the specified indicatorName (e.g., ".noexpand"). This is used to prune directories that are used for templating/generation but are not valid kube configs.

func RunCmdWithPrinters

func RunCmdWithPrinters(
	ctx context.Context,
	command string,
	args []string,
	extraEnv []string,
	blockedEnv map[string]struct{},
	stdoutPrinter Printer,
	stderrPrinter Printer,
) error

RunCmdWithPrinters runs a command with output streamed via custom printer functions. Adapted from example in https://github.com/golang/go/issues/19685#issuecomment-288949629.

func WriteFiles

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

WriteFiles takes a map of paths to file contents and uses this to write out files to the file system.

Types

type Printer

type Printer func(input string)

Printer is a function that prints out a string, e.g. to stdout.

func LogrusDebugPrinter

func LogrusDebugPrinter(prefix string) Printer

LogrusDebugPrinter returns a printer that prints via logrus at the debug level.

func LogrusInfoPrinter

func LogrusInfoPrinter(prefix string) Printer

LogrusInfoPrinter returns a printer that prints via logrus at the info level.

func LogrusWarnPrinter

func LogrusWarnPrinter(prefix string) Printer

LogrusWarnPrinter returns a printer that prints via logrus at the warn level.

Jump to

Keyboard shortcuts

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