Documentation
¶
Index ¶
- func AssertLocalHTTPContent(t *testing.T, rawURL string, wantContent string, opts ...RequestOption) bool
- func Chdir(dirPath string) func()
- func CheckGoroutineOutput(t *testing.T, out string)
- func CleanupDir(dir string)
- func ClearDockerEnv()
- func ContainerCheck(checkName string, checkState string) (bool, error)
- func CopyGlobalDdevDir(t *testing.T) string
- func CreateTmpDir(prefix string) string
- func GetCachedArchive(_, _, internalExtractionPath, sourceURL string) (string, string, error)
- func OsTempDir() (string, error)
- func RequireLocalHTTPContent(t *testing.T, rawURL string, wantContent string, opts ...RequestOption)
- func ResetGlobalDdevDir(t *testing.T, tmpXdgConfigHomeDir string)
- func SetTestHome(t *testing.T, home string)
- type LocalHTTPResponse
- type PortPair
- type RequestOption
- func WithAlsoContains(substrings ...string) RequestOption
- func WithBackoff(initial time.Duration) RequestOption
- func WithExpectStatus(code int) RequestOption
- func WithMaxAttempts(n int) RequestOption
- func WithMessagef(format string, args ...any) RequestOption
- func WithTimeout(d time.Duration) RequestOption
- type TestSite
- type URIWithExpect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLocalHTTPContent ¶ added in v1.25.3
func AssertLocalHTTPContent(t *testing.T, rawURL string, wantContent string, opts ...RequestOption) bool
AssertLocalHTTPContent is the non-fatal version of RequireLocalHTTPContent (like assert.Contains): it marks the test failed but lets it keep running, and returns whether the content was found. Prefer it in loops where you want to check every URL instead of stopping at the first failure.
func Chdir ¶
func Chdir(dirPath string) func()
Chdir will change to the directory for the site specified by TestSite. It returns an anonymous function which will return to the original working directory when called.
func CheckGoroutineOutput ¶ added in v1.23.0
CheckGoroutineOutput makes sure that goroutines aren't beyond specified level
func ClearDockerEnv ¶
func ClearDockerEnv()
ClearDockerEnv unsets env vars set in platform DockerEnv() so that they can be set by another test run.
func ContainerCheck ¶
ContainerCheck determines if a given container name exists and matches a given state
func CopyGlobalDdevDir ¶ added in v1.23.2
CopyGlobalDdevDir creates a temporary global config directory for DDEV using a temporary directory which is set to $DDEV_XDG_CONFIG_HOME/ddev Don't forget to run ResetGlobalDdevDir(t, tmpXdgConfigHomeDir) in the test's cleanup function.
func CreateTmpDir ¶
CreateTmpDir creates a temporary directory in the homedir and returns its path as a string. It's important that it's in homedir since Colima doesn't mount things outside that.
func GetCachedArchive ¶
GetCachedArchive returns a directory populated with the contents of the specified archive, either from cache or from downloading and creating cache. siteName is the site.Name used for storage prefixString is the prefix used to disambiguate downloads and extracts internalExtractionPath is the place in the archive to start extracting sourceURL is the actual URL to download. Returns the extracted path, the tarball path (both possibly cached), and an error value.
func OsTempDir ¶
OsTempDir gets os.TempDir() (usually provided by $TMPDIR) but expands any symlinks found within it. This wrapper function can prevent problems with docker-for-mac trying to use /var/..., which is not typically shared/mounted. It will be expanded via the /var symlink to /private/var/...
func RequireLocalHTTPContent ¶ added in v1.25.3
func RequireLocalHTTPContent(t *testing.T, rawURL string, wantContent string, opts ...RequestOption)
RequireLocalHTTPContent checks that rawURL returns the expected status (default 200, see WithExpectStatus) and a body containing wantContent, stopping the test (t.FailNow) if not, like require.Contains. By default, it makes a single request; use WithMaxAttempts to keep trying until the content shows up (handy when it appears a moment later, e.g. a xhprof run written after the response). To look at the response yourself, use GetLocalHTTPResponse instead.
func ResetGlobalDdevDir ¶ added in v1.23.2
ResetGlobalDdevDir removes temporary $DDEV_XDG_CONFIG_HOME directory
func SetTestHome ¶ added in v1.25.3
SetTestHome sets HOME (and USERPROFILE on Windows) to the given directory. On Windows, os.UserHomeDir() reads USERPROFILE, not HOME, so both must be set for tests that need to isolate the home directory.
Types ¶
type LocalHTTPResponse ¶ added in v1.25.3
LocalHTTPResponse holds the status and headers we return to callers. The body is returned separately as a string, so there is no open response body to leak (unlike *http.Response).
func GetLocalHTTPResponse ¶ added in v1.1.0
func GetLocalHTTPResponse(t *testing.T, rawURL string, opts ...RequestOption) (string, *LocalHTTPResponse, error)
GetLocalHTTPResponse requests rawURL on the local Docker IP and returns the body and the response status/headers. A status other than expected (default 200, see WithExpectStatus) comes back as an error, with the body still returned. Like assert, it never fails the test. By default, it makes a single request; use WithMaxAttempts/WithBackoff/WithTimeout/WithExpectStatus to tune it.
type RequestOption ¶ added in v1.25.3
type RequestOption func(*requestConfig)
RequestOption configures a local HTTP request.
func WithAlsoContains ¶ added in v1.25.3
func WithAlsoContains(substrings ...string) RequestOption
WithAlsoContains adds more substrings the body must contain, on top of the wantContent passed to Assert/RequireLocalHTTPContent. All must be present, and retries continue until they are. No effect on GetLocalHTTPResponse.
func WithBackoff ¶ added in v1.25.3
func WithBackoff(initial time.Duration) RequestOption
WithBackoff doubles the delay after each attempt (starting at initial, capped at the timeout) instead of the fixed 1s delay. Zero or negative initial keeps the default 1s start delay.
func WithExpectStatus ¶ added in v1.25.3
func WithExpectStatus(code int) RequestOption
WithExpectStatus sets the status code treated as success; any other code is an error (and triggers a retry). Defaults to 200 (http.StatusOK).
func WithMaxAttempts ¶ added in v1.25.3
func WithMaxAttempts(n int) RequestOption
WithMaxAttempts sets the total number of requests to make (the first try plus any retries); values below 1 become 1. Use it to keep trying until the expected content shows up or a temporary error goes away.
func WithMessagef ¶ added in v1.25.3
func WithMessagef(format string, args ...any) RequestOption
WithMessagef adds a printf-style message shown when an Assert/RequireLocalHTTPContent check fails. No effect on GetLocalHTTPResponse.
func WithTimeout ¶ added in v1.25.3
func WithTimeout(d time.Duration) RequestOption
WithTimeout sets the per-request timeout. Zero or negative disables it.
type TestSite ¶
type TestSite struct {
// Name is the generic name of the site, and is used as the default dir.
Name string
// Provide ability to disable
Disable bool
// SourceURL is the URL of the source code tarball to be used for building the site.
SourceURL string
// ArchiveExtractionPath is the relative path within the tarball which should be extracted, ending with /
ArchiveInternalExtractionPath string
// FullSiteTarballURL is the URL of the tarball of a full site archive used for testing import.
FullSiteTarballURL string
// FilesTarballURL is the URL of the tarball of file uploads used for testing file import.
FilesTarballURL string
// FilesZipballURL is the URL of the zipball of file uploads used for testing file import.
FilesZipballURL string
// DBTarURL is the URL of the database dump tarball used for testing database import.
DBTarURL string
// DBZipURL is the URL of an optional zip-style db dump.
DBZipURL string
// Dir is the rooted full path of the test site
Dir string
// HTTPProbeURI is the URI that can be probed to look for a working web container
HTTPProbeURI string
// WebEnvironment is strings that will be used in web_environment
WebEnvironment []string
// WebserverType if needed (apache-fpm, generic)
WebserverType string
// PretestCmd will be executed in web-entrypoint.d script before
// daemons are started inside the web container
PretestCmd string
// Docroot is the subdirectory within the site that is the root/index.php
Docroot string
// Type is the type of application. This can be specified when a config file is not present
// for a test site.
Type string
// Safe200URIWithExpectation provides a static URI with contents that it can be expected to contain.
Safe200URIWithExpectation URIWithExpect
// DynamicURI provides a dynamic (after db load) URI with contents we can expect.
DynamicURI URIWithExpect
// UploadDirs overrides the dirs used for upload_dirs
UploadDirs []string
// FilesImageURI is URI to a file loaded by import-files that is a jpg.
FilesImageURI string
// FullSiteArchiveExtPath is the path that should be extracted from inside an archive when
// importing the files from a full site archive
FullSiteArchiveExtPath string
}
TestSite describes a site for testing, with name, URL of tarball, and optional dir.
func (*TestSite) Chdir ¶
func (site *TestSite) Chdir() func()
Chdir will change to the directory for the site specified by TestSite.
type URIWithExpect ¶ added in v1.3.0
URIWithExpect pairs a URI like "/readme.html" with some substring content "should be found in URI"