utils

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 17 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 PollE added in v0.8.0

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

Polls on a particular condition function while the returns true. Returns an error 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 StringFromTextAndArgs added in v0.10.0

func StringFromTextAndArgs(msgAndArgs ...interface{}) string

StringFromTextAndArgs converts msg and args to formatted text

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 WithHTTPClient added in v0.7.0

func WithHTTPClient(c *http.Client) assertOption

WithHTTPClient specifies an HTTP client for the AssertHTTP use.

func WithHTTPRequestRetries added in v0.8.0

func WithHTTPRequestRetries(count int, interval time.Duration) assertOption

WithHTTPRequestRetries specifies a HTTP request retry policy.

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 AssertHTTP added in v0.7.0

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

AssertHTTP provides a collection of HTTP asserts.

func NewAssertHTTP added in v0.7.0

func NewAssertHTTP(opts ...assertOption) *AssertHTTP

NewAssertHTTP creates a new AssertHTTP with option overrides.

func (*AssertHTTP) AssertResponse added in v0.7.0

func (ah *AssertHTTP) AssertResponse(t testing.TB, r *http.Request, wantCode int, want ...string)

AssertResponse runs httpResponse without retry.

func (*AssertHTTP) AssertResponseWithRetry added in v0.7.0

func (ah *AssertHTTP) AssertResponseWithRetry(t testing.TB, r *http.Request, wantCode int, want ...string)

AssertResponseWithRetry runs httpResponse and retries on errors outside client control.

func (*AssertHTTP) AssertSuccess added in v0.7.0

func (ah *AssertHTTP) AssertSuccess(t testing.TB, r *http.Request)

AssertSuccess runs httpRequest without retry.

func (*AssertHTTP) AssertSuccessWithRetry added in v0.7.0

func (ah *AssertHTTP) AssertSuccessWithRetry(t testing.TB, r *http.Request)

AssertSuccessWithRetry runs httpRequest and retries on errors outside client control.

type PollConditionError added in v0.8.0

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

PollConditionError is an error returned on the final PollE attempt.

func (*PollConditionError) Error added in v0.8.0

func (e *PollConditionError) Error() string

func (*PollConditionError) Unwrap added in v0.8.0

func (e *PollConditionError) Unwrap() error

type PollParameterError added in v0.8.0

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

PollParameterError is returend by PollE when input parameters are invalid.

func (*PollParameterError) Error added in v0.8.0

func (e *PollParameterError) Error() string

type PollRetryLimitExceededError added in v0.8.0

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

PollRetryLimitExceededError is returned by PollE when retries exceed numRetries.

func (*PollRetryLimitExceededError) Error added in v0.8.0

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