Documentation
¶
Overview ¶
Package testutil provides helpers for unit tests.
Index ¶
- Variables
- func Args(args string) []string
- func AssertBool(t *testing.T, want, have bool)
- func AssertContentFlag(wantError string, args []string, fixture string, content string, t *testing.T)
- func AssertEqual(t *testing.T, want, have interface{})
- func AssertErrorContains(t *testing.T, err error, target string)
- func AssertNoError(t *testing.T, err error)
- func AssertRemediationErrorContains(t *testing.T, err error, target string)
- func AssertString(t *testing.T, want, have string)
- func AssertStringContains(t *testing.T, s, substr string)
- func CloneVersionError(i *fastly.CloneVersionInput) (*fastly.Version, error)
- func CloneVersionResult(version int) func(i *fastly.CloneVersionInput) (*fastly.Version, error)
- func ListVersions(i *fastly.ListVersionsInput) ([]*fastly.Version, error)
- func ListVersionsError(i *fastly.ListVersionsInput) ([]*fastly.Version, error)
- func MakeTempFile(t *testing.T, contents string) string
- func MustParseTimeRFC3339(s string) *time.Time
- type AppRunArgs
- type TestScenario
Constants ¶
This section is empty.
Variables ¶
Date is a consistent date object used by all tests.
var ErrAPI = errors.New("test api error")
ErrAPI represents a generic API error.
Functions ¶
func Args ¶ added in v0.32.0
Args is a simple wrapper function designed to accept a CLI command (including flags) and return it as a slice for consumption by app.Run().
func AssertBool ¶
AssertBool fatals a test if the parameters aren't equal.
func AssertContentFlag ¶ added in v0.32.0
func AssertContentFlag(wantError string, args []string, fixture string, content string, t *testing.T)
AssertContentFlag errors a test scenario if the --content flag value hasn't been parsed as expected.
Example: if --content is passed a file path, then we expect the testdata/<fixture> to have been read, otherwise we expect the given flag value to have been used as is.
func AssertEqual ¶ added in v0.9.0
AssertEqual fatals a test if the parameters aren't equal.
func AssertErrorContains ¶
AssertErrorContains fatals a test if the error's Error string doesn't contain target. As a special case, if target is the empty string, we assume the error should be nil.
func AssertNoError ¶
AssertNoError fatals a test if the error is not nil.
func AssertRemediationErrorContains ¶ added in v0.8.0
AssertRemediationErrorContains fatals a test if the error's RemediationError remediation string doesn't contain target. As a special case, if target is the empty string, we assume the error should be nil.
func AssertString ¶
AssertString fatals a test if the parameters aren't equal.
func AssertStringContains ¶
AssertStringContains fatals a test if the string doesn't contain a substring.
func CloneVersionError ¶ added in v0.31.0
func CloneVersionError(i *fastly.CloneVersionInput) (*fastly.Version, error)
CloneVersionError returns a generic error message when attempting to clone a service version.
func CloneVersionResult ¶ added in v0.31.0
CloneVersionResult returns a function which returns a specific cloned version.
func ListVersions ¶ added in v0.31.0
func ListVersions(i *fastly.ListVersionsInput) ([]*fastly.Version, error)
ListVersions returns a list of service versions in different states.
The first element is active, the second is locked, the third is editable.
NOTE: consult the entire test suite before adding any new entries to the returned type as the tests currently use testutil.CloneVersionResult() as a way of making the test output and expectations as accurate as possible.
func ListVersionsError ¶ added in v0.31.0
func ListVersionsError(i *fastly.ListVersionsInput) ([]*fastly.Version, error)
ListVersionsError returns a generic error message when attempting to list service versions.
func MakeTempFile ¶ added in v0.21.0
MakeTempFile creates a tempfile with the given contents and returns its path
func MustParseTimeRFC3339 ¶
MustParseTimeRFC3339 is a small helper to initialize time constants.
Types ¶
type AppRunArgs ¶ added in v0.32.0
type AppRunArgs struct {
AppConfigFile string
Args []string
CLIVersioner update.Versioner
ClientFactory func(token, endpoint string) (api.Interface, error)
Env config.Environment
File config.File
HTTPClient *http.Client
In io.Reader
Out io.Writer
}
AppRunArgs represents the structure of the args passed into app.Run().
NOTE: in future the app.Run() signature will be updated to accept a struct, and that will mean any references to the AppRunArgs testing struct can be replaced with the app.Run() struct.
func NewAppRunArgs ¶ added in v0.32.0
NewAppRunArgs returns a struct that can be used to populate a call to app.Run() while the majority of fields will be pre-populated and only those fields commonly changed for testing purposes will need to be provided.