utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const RUN_STAGE_ENV_VAR = "RUN_STAGE"

Variables

This section is empty.

Functions

func BinaryInPath

func BinaryInPath(bin string) error

BinaryInPath checks if a given binary is in path.

func DeleteFromResult

func DeleteFromResult(t testing.TB, pth string, r gjson.Result) gjson.Result

DeleteFromResult deletes given path from result and returns the modified result

func GetFirstMatchResult

func GetFirstMatchResult(t testing.TB, rs []gjson.Result, k, v string) gjson.Result

GetFirstMatchResult returns the first matching result with a given k/v

func GetLoggerFromT

func GetLoggerFromT() *logger.Logger

GetLoggerFromT returns a logger based on test verbosity

func GetResultStrSlice

func GetResultStrSlice(rs []gjson.Result) []string

GetResultStrSlice parses results into a string slice

func GetWD added in v0.5.1

func GetWD(t testing.TB) string

Get the environment Working Directory.

func LoadJSON

func LoadJSON(t testing.TB, path string) gjson.Result

LoadJSON reads and parses a json file into a gjson.Result. It fails test if not unable to parse.

func MinSemver added in v0.5.0

func MinSemver(gotSemver string, minSemver string) error

MinSemver validates gotSemver is not less than minSemver

func NewTestFileLogger added in v0.3.0

func NewTestFileLogger(t *testing.T, pth string) (*logger.Logger, func(t *testing.T))

NewTestFileLogger returns a TestFileLogger logger that can be used with the WithLogger option.

func ParseJSONResult

func ParseJSONResult(t testing.TB, j string) gjson.Result

ParseJSONResult converts a JSON string into gjson result

func Poll

func Poll(t testing.TB, condition func() (bool, error), numRetries int, interval time.Duration)

Polls on a particular condition function while the returns true. It fails the test if the condition is not met within numRetries.

func RandStr

func RandStr(l int) string

RandStr generates rand lowercase strings of length l

func RunStage

func RunStage(stageName string, stage func())

RunStage runs stage if stageName matches RUN_STAGE env var or RUN_STAGE is unset. Similar to terratest RunStage but instead of skipping using env var, we match using envvar.

func SetEnv

func SetEnv(t testing.TB, key string, value string)

SetEnv set a environment variable.

func ValFromEnv

func ValFromEnv(t testing.TB, k string) string

ValFromEnv returns value for a given env var. It fails test if not set.

func WriteTmpFile

func WriteTmpFile(data string) (string, error)

WriteTmpFile writes data to a temp file and returns the path.

func WriteTmpFileWithExtension added in v0.2.0

func WriteTmpFileWithExtension(data string, extension string) (string, error)

WriteTmpFileWithExtension writes data to a temp file with given extension and returns the path.

Types

type TestFileLogger added in v0.3.0

type TestFileLogger struct {
	// contains filtered or unexported fields
}

TestFileLogger is a logger that writes to disk instead of stdout. This is useful when you want to redirect verbose logs of long running tests to disk.

func (TestFileLogger) Close added in v0.3.0

func (fl TestFileLogger) Close(t *testing.T)

func (TestFileLogger) Logf added in v0.3.0

func (fl TestFileLogger) Logf(t terraTesting.TestingT, format string, args ...interface{})

Jump to

Keyboard shortcuts

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