testhelper

package
v0.0.0-...-ee148e2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(t *testing.T, boolStatement bool, errorValue interface{})

Assert checks that the boolean statement is true. If not, it fails the test with the given error value. Assert streamlines test checks.

func CheckResources

func CheckResources(haps ...HostAndPort) error

CheckResources ensures that any resources needed for an integration test are available. If a resource is not available, it returns an error.

func IntegrationDBTestSetup

func IntegrationDBTestSetup(t *testing.T, db *sql.DB) (func(t *testing.T, db *sql.DB), error)

IntegrationDBTestSetup ensures that the database is empty before running any tests and returns a teardown function that will delete all entries in the database.

func IntegrationDBTestSetupMain

func IntegrationDBTestSetupMain(db *sql.DB) (func(db *sql.DB), error)

IntegrationDBTestSetupMain ensures that the database is empty before running any tests and returns a teardown function that will delete all entries in the database.

Types

type HostAndPort

type HostAndPort struct {
	Host string
	Port string
}

HostAndPort holds the host and port information for a resource.

type TestClient

type TestClient struct {
	http.Client
	// contains filtered or unexported fields
}

TestClient is test wrapper around an http client, allowing http responses to be mocked.

func NewTestClient

func NewTestClient(handler http.Handler) *TestClient

NewTestClient creates a new TestClient using an httptest TLS Server. Any http requests using this client will be handled by 'handler'.

func NewTestClientNoTLS

func NewTestClientNoTLS(handler http.Handler) *TestClient

func NewTestClientWith404

func NewTestClientWith404() *TestClient

NewTestClientWith404 creates a new TestClient using an httptest TLS Server, and requests are responded to with a 404 response code.

func NewTestClientWith406

func NewTestClientWith406() *TestClient

NewTestClientWith406 creates a new TestClient using an httptest TLS Server, and requests are responded to with a 406 response code.

func NewTestClientWith502

func NewTestClientWith502() *TestClient

NewTestClientWith502 creates a new TestClient using an httptest TLS Server, and requests are responded to with a 502 response code.

func NewTestClientWithResponse

func NewTestClientWithResponse(response []byte) *TestClient

NewTestClientWithResponse creates a new TestClient using an httptest TLS Server, and requests are responded to using the given response byte string.

func (*TestClient) Close

func (tc *TestClient) Close()

Close closes resources associated with the test client and should be called after every instantiation of the client.

Jump to

Keyboard shortcuts

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