Documentation ¶
Overview ¶
(C) Copyright 2019 Intel Corporation.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.
(C) Copyright 2019 Intel Corporation.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.
Index ¶
- Constants
- func All(ss []string, f func(string) bool) bool
- func Any(ss []string, f func(string) bool) bool
- func AppendFile(path string) (*os.File, error)
- func AssertEqual(t *testing.T, a interface{}, b interface{}, message string)
- func AssertFalse(t *testing.T, b bool, message string)
- func AssertStringsEqual(t *testing.T, a []string, b []string, message string)
- func AssertTrue(t *testing.T, b bool, message string)
- func CmpErr(t *testing.T, want, got error)
- func CmpErrBool(want, got error) bool
- func CreateTestDir(t *testing.T) (string, func())
- func CreateTestSocket(t *testing.T, sockPath string) (*net.UnixListener, func())
- func DefaultCmpOpts() []cmp.Option
- func ExpectError(t *testing.T, actualErr error, expectedMessage string, desc interface{})
- func Filter(ss []string, f func(string) bool) (nss []string)
- func FindBinary(binName string) (string, error)
- func GetAdjacentPath(inPath string) (string, error)
- func GetConsent(log logging.Logger) bool
- func GetFilePaths(dir string, ext string) ([]string, error)
- func GetWorkingPath(inPath string) (string, error)
- func HasPort(addr string) bool
- func Includes(ss []string, target string) bool
- func Index(ss []string, target string) int
- func IsAlphabetic(s string) bool
- func LoadTestFiles(inFile string, outFile string) (inputs [][]string, outputs [][]string, err error)
- func Map(ss []string, f func(string) string) (nss []string)
- func MockCheckMountOk(path string) error
- func ParseInts(in string) (ints []uint32, err error)
- func Pluralise(s string, n int) string
- func PrintStructs(name string, i interface{})
- func ResolvePath(inPath string, defaultPath string) (outPath string, err error)
- func Run(cmd string) error
- func ScrubEnvironment(blacklist []string)
- func ScrubEnvironmentExcept(whitelist []string)
- func ScrubProxyVariables()
- func SetupTestListener(t *testing.T, conn chan *net.UnixConn) (string, func())
- func ShowBufferOnFailure(t *testing.T, buf fmt.Stringer)
- func SplitFile(path string) (sections [][]string, err error)
- func SplitPort(addrPattern string, defaultPort int) (string, string, error)
- func StructsToString(i interface{}) (lines string, err error)
- func SyncDir(path string) (err error)
- func TruncFile(path string) (*os.File, error)
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- func WriteSlice(path string, slice []string) (err error)
- func WriteString(path string, s string) error
Constants ¶
const DisableProxyScrubEnv = "DAOS_DISABLE_PROXY_SCRUB"
const UtilLogDepth = 4
UtilLogDepth signifies stack depth, set calldepth on calls to logger so log message context refers to caller not callee.
Variables ¶
This section is empty.
Functions ¶
func AppendFile ¶
AppendFile appends to existing or creates new file with default options
func AssertEqual ¶
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.
func AssertFalse ¶
AssertFalse asserts b is false
func AssertStringsEqual ¶
AssertStringsEqual sorts string slices before comparing.
func AssertTrue ¶
AssertTrue asserts b is true
func CmpErr ¶
CmpErr compares two errors for equality or at least close similarity in their messages.
func CmpErrBool ¶ added in v0.8.0
CmpErrBool compares two errors and returns a boolean value indicating equality or at least close similarity between their messages.
func CreateTestDir ¶
CreateTestDir creates a temporary test directory. It returns the path to the directory and a cleanup function.
func CreateTestSocket ¶ added in v0.9.0
func CreateTestSocket(t *testing.T, sockPath string) (*net.UnixListener, func())
CreateTestSocket creates a Unix Domain Socket that can listen for connections on a given path. It returns the listener and a cleanup function.
func DefaultCmpOpts ¶
DefaultCmpOpts gets default go-cmp comparison options for tests.
func ExpectError ¶
ExpectError asserts error contains expected message
func FindBinary ¶
FindBinary attempts to locate the named binary by checking $PATH first. If the binary is not found in $PATH, look in the directory containing the running process' binary as well as the working directory.
func GetAdjacentPath ¶ added in v0.9.0
GetAdjacentPath retrieves path relative to the binary used to launch the currently running process.
func GetFilePaths ¶
GetFilePaths return full file paths in given directory with matching file extensions
func GetWorkingPath ¶ added in v0.9.0
GetWorkingPath retrieves path relative to the current working directory when invoking the current process.
func HasPort ¶ added in v0.9.0
HasPort checks if addr specifies a port. This only works with IPv4 addresses at the moment.
func IsAlphabetic ¶
IsAlphabetic checks of a string just contains alphabetic characters.
func LoadTestFiles ¶
func LoadTestFiles(inFile string, outFile string) ( inputs [][]string, outputs [][]string, err error)
LoadTestFiles reads inputs and outputs from file and do basic sanity checks. Both files contain entries of multiple lines separated by blank line. Return inputs and outputs, both of which are slices of string slices.
func MockCheckMountOk ¶
MockCheckMountOk mocks CheckMount and always returns nil error.
func PrintStructs ¶
func PrintStructs(name string, i interface{})
PrintStructs dumps friendly YAML representation of structs to stdout proceeded with "name" identifier.
func ResolvePath ¶ added in v0.9.0
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). Use case is specific to config files.
func ScrubEnvironment ¶
func ScrubEnvironment(blacklist []string)
ScrubEnvironment modifies the environment variables set for this process and any children which inherit its environment by unsetting any variables supplied in the blacklist.
func ScrubEnvironmentExcept ¶
func ScrubEnvironmentExcept(whitelist []string)
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.
func ScrubProxyVariables ¶
func ScrubProxyVariables()
ScrubProxyVariables removes proxy variables from the process environment.
func SetupTestListener ¶ added in v0.9.0
SetupTestListener sets up a Unix Domain Socket in a temp directory to listen and receive one connection. The server-side connection object is sent through the conn channel when a client connects. It returns the path to the socket, to allow the client to connect, and a cleanup function.
func ShowBufferOnFailure ¶
ShowBufferOnFailure displays captured output on test failure. Should be run via defer in the test function.
func SplitFile ¶
SplitFile separates file content into contiguous sections separated by a blank line.
func SplitPort ¶ added in v0.9.0
SplitPort separates port from host in address and can apply default port if address doesn't contain one.
func StructsToString ¶
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.
func SyncDir ¶
SyncDir flushes all prior modifications to a directory. This is required if one modifies a directory (e.g., by creating a new file in it) and needs to wait for this modification to become persistent.
func WriteFileAtomic ¶
WriteFileAtomic mimics ioutil.WriteFile, but it makes sure the file is either successfully written persistently or untouched.
func WriteSlice ¶
WriteSlice writes string slice to specified file, overwriting and creating if non-existent.
func WriteString ¶
WriteString writes string to specified file, wrapper around WriteSlice.
Types ¶
This section is empty.