generic

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile added in v0.0.11

func CopyFile(t *testing.T, src, dest string)

CopyFile copies src to dest atomically by creating an intermediate temporary file and then doing an atomic rename.

func FilesEqual added in v0.0.6

func FilesEqual(t *testing.T, expected, actual string)

FilesEqual compares the contents of two files to see if they're equal. If not, a unified diff is displayed showing the differences.

func GenerateSelfSignedCert added in v0.0.3

func GenerateSelfSignedCert(destCert, destKey io.Writer, hosts []string) error

GenerateSelfSignedCert generates a self-signed RSA certificate for testing purposes.

func JSONResponse added in v0.0.4

func JSONResponse(t *testing.T, code int, body any) *http.Response

JSONResponse sets up a basic http.Response with an object in the body of the response.

func MustCommand added in v0.0.8

func MustCommand(t *testing.T, command string, args ...string)

MustCommand executes the command and requires a clean exit code.

func NewRandomPort added in v0.0.2

func NewRandomPort(t *testing.T) string

NewRandomPort identifies a port on the localhost interface for use during tests and returns the string in interface:port format. It uses similar methodology to how the net/http/httptest server chooses a port.

func NewTestClient added in v0.0.4

func NewTestClient(fn RoundTripFunc) *http.Client

NewTestClient returns *http.Client with Transport replaced to avoid making real calls.

func RequireGID added in v0.0.10

func RequireGID(t *testing.T, path string, group int)

func RequireGroup added in v0.0.10

func RequireGroup(t *testing.T, path string, groupName string)

func RequireJSONValue added in v0.0.13

func RequireJSONValue(t *testing.T, input, key string, value any)

RequireJSONValue takes a JSON string as input, then checks that the key matches the value.

func RequireOwner added in v0.0.10

func RequireOwner(t *testing.T, path string, username string)

func RequirePerms added in v0.0.10

func RequirePerms(t *testing.T, path string, perms fs.FileMode)

func RequireUID added in v0.0.10

func RequireUID(t *testing.T, path string, owner int)

func SetEnvs

func SetEnvs(t *testing.T, envs map[string]string) func(t *testing.T)

SetEnvs sets environment variables, preserving any existing values from the envioronment, and restoring when the test is finished.

func Walk added in v0.0.6

func Walk(t *testing.T, root string) []string

Walk traverses a directory tree and returns the list of files discovered.

Types

type CertificateAuthority added in v0.0.7

type CertificateAuthority struct {
	Cert    *x509.Certificate
	PrivKey *rsa.PrivateKey

	PEMCert []byte
	PEMKey  []byte
}

CertificateAuthority is a test CA that is capable of signing certs for use during testing.

func NewCertificateAuthority added in v0.0.7

func NewCertificateAuthority() (*CertificateAuthority, error)

NewCertificateAuthority initializes a CertificateAuthority.

func (*CertificateAuthority) MakeCert added in v0.0.7

func (c *CertificateAuthority) MakeCert(destCert, destKey io.Writer, hosts ...string) error

MakeCert is a helper method that will generate a cert using the hosts and/or ips in the hosts array.

func (*CertificateAuthority) SignCert added in v0.0.7

func (c *CertificateAuthority) SignCert(template *x509.Certificate, destCert, destKey io.Writer) error

SignCert will sign a certificate with the CA. This method gives you more control of the cert than the MakeCert method does.

type RoundTripFunc added in v0.0.4

type RoundTripFunc func(req *http.Request) *http.Response

RoundTripFunc is a function that will be called to fulfill and http request.

func (RoundTripFunc) RoundTrip added in v0.0.4

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes the round trip, calling the underlying function.

Jump to

Keyboard shortcuts

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