testlib

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testlib provides common test utilities.

Index

Constants

This section is empty.

Variables

View Source
var DumbCourier = dumbCourier{}

DumbCourier always succeeds delivery, and ignores everything.

Functions

func GenerateCert

func GenerateCert(path string) (*tls.Config, error)

GenerateCert generates a new, INSECURE self-signed certificate and writes it to a pair of (cert.pem, key.pem) files to the given path. Note the certificate is only useful for testing purposes.

func GetFreePort

func GetFreePort() string

GetFreePort returns a free TCP port. This is hacky and not race-free, but it works well enough for testing purposes.

func MustTempDir

func MustTempDir(t *testing.T) string

MustTempDir creates a temporary directory, or dies trying.

func RemoveIfOk

func RemoveIfOk(t *testing.T, dir string)

RemoveIfOk removes the given directory, but only if we have not failed. We want to keep the failed directories for debugging.

func Rewrite

func Rewrite(t *testing.T, path, contents string) error

Rewrite a file with the given contents.

func WaitFor

func WaitFor(f func() bool, d time.Duration) bool

WaitFor f to return true (returns true), or d to pass (returns false).

Types

type TestCourier

type TestCourier struct {
	Requests []*deliverRequest
	ReqFor   map[string]*deliverRequest
	sync.Mutex
	// contains filtered or unexported fields
}

TestCourier never fails, and always remembers everything.

func NewTestCourier

func NewTestCourier() *TestCourier

NewTestCourier returns a new, empty TestCourier instance.

func (*TestCourier) Deliver

func (tc *TestCourier) Deliver(from string, to string, data []byte) (error, bool)

Deliver the given mail (saving it in tc.Requests).

func (*TestCourier) Expect

func (tc *TestCourier) Expect(i int)

Expect i mails to be delivered.

func (*TestCourier) Wait

func (tc *TestCourier) Wait()

Wait until all mails have been delivered.

Jump to

Keyboard shortcuts

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