testcommon

package
v1.21.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chdir

func Chdir(path 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 CleanupDir

func CleanupDir(dir string)

CleanupDir removes a directory specified by string.

func ClearDockerEnv

func ClearDockerEnv()

ClearDockerEnv unsets env vars set in platform DockerEnv() so that they can be set by another test run.

func ContainerCheck

func ContainerCheck(checkName string, checkState string) (bool, error)

ContainerCheck determines if a given container name exists and matches a given state

func CreateTmpDir

func CreateTmpDir(prefix string) string

CreateTmpDir creates a temporary directory and returns its path as a string.

func EnsureLocalHTTPContent added in v1.1.0

func EnsureLocalHTTPContent(t *testing.T, rawurl string, expectedContent string, timeoutSeconds ...int) (*http.Response, error)

EnsureLocalHTTPContent will verify a URL responds with a 200 and expected content string

func GetCachedArchive

func GetCachedArchive(siteName string, prefixString string, internalExtractionPath string, sourceURL string) (string, string, error)

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 GetLocalHTTPResponse added in v1.1.0

func GetLocalHTTPResponse(t *testing.T, rawurl string, timeoutSecsAry ...int) (string, *http.Response, error)

GetLocalHTTPResponse takes a URL and optional timeout in seconds, hits the local docker for it, returns result Returns error (with the body) if not 200 status code.

func OsTempDir

func OsTempDir() (string, error)

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/...

Types

type PortPair added in v1.3.0

type PortPair struct {
	HTTPPort  string
	HTTPSPort string
}

PortPair is for tests to use naming portsets for tests

type TestSite

type TestSite struct {
	// Name is the generic name of the site, and is used as the default dir.
	Name string
	// 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
	// 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
	// UploadDir overrides the dir used for upload_dir
	UploadDir 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.

func (*TestSite) Cleanup

func (site *TestSite) Cleanup()

Cleanup removes the archive and codebase extraction for a site after a test run has completed.

func (*TestSite) Prepare

func (site *TestSite) Prepare() error

Prepare downloads and extracts a site codebase to a temporary directory.

type URIWithExpect added in v1.3.0

type URIWithExpect struct {
	URI    string
	Expect string
}

URIWithExpect pairs a URI like "/readme.html" with some substring content "should be found in URI"

Jump to

Keyboard shortcuts

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