# README
Common
Common utilities for file access, collection manipulation (including some functional helper methods), unit tests and mocks among others. This package will be imported from multiple other packages under its parent directory and to avoid cyclical import dependencies files in this package should not import from peer packages unless absolutely necessary.
# Functions
All returns true if all strings returns true from f.
Any returns true if any of the strings in the slice returns true from f.
AppendFile appends to existing or creates new file with default options.
AssertEqual asserts b is equal to a
Whilst suitable in most situations, reflect.DeepEqual() may not be suitable for nontrivial struct element comparisons, go-cmp should then be used but will introduce a third party dep.
AssertFalse asserts b is false.
AssertStringsEqual sorts string slices before comparing.
AssertTrue asserts b is true.
CmpErr compares two errors for equality or at least close similarity in their messages.
CmpErrBool compares two errors and returns a boolean value indicating equality or at least close similarity between their messages.
CreateTestDir creates a temporary test directory.
CreateTestSocket creates a Unix Domain Socket that can listen for connections on a given path.
DefaultCmpOpts gets default go-cmp comparison options for tests.
ExpectError asserts error contains expected message.
Filter returns new slice with only strings that return true from f.
FindBinary attempts to locate the named binary by checking $PATH first.
GetAdjacentPath retrieves path relative to the binary used to launch the currently running process.
GetConsent scans stdin for yes/no.
GetFilePaths return full file paths in given directory with matching file extensions.
GetWorkingPath retrieves path relative to the current working directory when invoking the current process.
HasPort checks if addr specifies a port.
Includes returns true if string target in slice.
Index returns first index of target string, -1 if no match.
IsAlphabetic checks of a string just contains alphabetic characters.
LoadTestFiles reads inputs and outputs from file and do basic sanity checks.
Map returns new slice with f applied to each string in original.
MockCheckMountOk mocks CheckMount and always returns nil error.
ParseInts converts string of uint32s to uint32 array.
Pluralise appends "s" to input string unless n==1.
PrintStructs dumps friendly YAML representation of structs to stdout proceeded with "name" identifier.
ResolvePath simply returns an absolute path, appends input path to current working directory if input path not empty otherwise appends default path to location of running binary (adjacent).
Run executes command in os and builds useful error message.
ScrubEnvironment modifies the environment variables set for this process and any children which inherit its environment by unsetting any variables supplied in the blacklist.
ScrubEnvironmentExcept modifies the environment variables set for this process and any children which inherit its environment by unsetting any variables that are not supplied in the whitelist.
ScrubProxyVariables removes proxy variables from the process environment.
SetupTestListener sets up a Unix Domain Socket in a temp directory to listen and receive one connection.
ShowBufferOnFailure displays captured output on test failure.
SplitFile separates file content into contiguous sections separated by a blank line.
SplitPort separates port from host in address and can apply default port if address doesn't contain one.
StructsToString returns yaml representation (as a list of strings) of any interface but avoids fields/lines prefixed with xxx_ such as added by protobuf boilerplate.
SyncDir flushes all prior modifications to a directory.
TruncFile overrides existing or creates new file with default options.
WriteFileAtomic mimics ioutil.WriteFile, but it makes sure the file is either successfully written persistently or untouched.
WriteSlice writes string slice to specified file, overwriting and creating if non-existent.
WriteString writes string to specified file, wrapper around WriteSlice.
# Constants
No description provided by the author
UtilLogDepth signifies stack depth, set calldepth on calls to logger so log message context refers to caller not callee.