caddytest

package
v2.4.0-beta.1.0...-d29e99a Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Defaults{
	AdminPort:          2019,
	Certifcates:        []string{"/caddy.localhost.crt", "/caddy.localhost.key"},
	TestRequestTimeout: 5 * time.Second,
	LoadRequestTimeout: 5 * time.Second,
}

Default testing values

Functions

func AssertAdapt

func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string)

AssertAdapt adapts a config and then tests it against an expected result

func AssertLoadError

func AssertLoadError(t *testing.T, rawConfig string, configType string, expectedError string)

AssertLoadError will load a config and expect an error

func CompareAdapt

func CompareAdapt(t *testing.T, filename, rawConfig string, adapterName string, expectedResponse string) bool

CompareAdapt adapts a config and then compares it against an expected result

func CreateTestingTransport

func CreateTestingTransport() *http.Transport

CreateTestingTransport creates a testing transport that forces call dialing connections to happen locally

Types

type Defaults

type Defaults struct {
	// Port we expect caddy to listening on
	AdminPort int
	// Certificates we expect to be loaded before attempting to run the tests
	Certifcates []string
	// TestRequestTimeout is the time to wait for a http request to
	TestRequestTimeout time.Duration
	// LoadRequestTimeout is the time to wait for the config to be loaded against the caddy server
	LoadRequestTimeout time.Duration
}

Defaults store any configuration required to make the tests run

type Tester

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

Tester represents an instance of a test client.

func NewTester

func NewTester(t *testing.T) *Tester

NewTester will create a new testing client with an attached cookie jar

func (*Tester) AssertDeleteResponse

func (tc *Tester) AssertDeleteResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string)

AssertDeleteResponse request a URI and expect a statusCode and body text

func (*Tester) AssertGetResponse

func (tc *Tester) AssertGetResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string)

AssertGetResponse GET a URI and expect a statusCode and body text

func (*Tester) AssertPatchResponseBody

func (tc *Tester) AssertPatchResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string)

AssertPatchResponseBody PATCH to a URI and assert the response code and body

func (*Tester) AssertPostResponseBody

func (tc *Tester) AssertPostResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string)

AssertPostResponseBody POST to a URI and assert the response code and body

func (*Tester) AssertPutResponseBody

func (tc *Tester) AssertPutResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string)

AssertPutResponseBody PUT to a URI and assert the response code and body

func (*Tester) AssertRedirect

func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, expectedStatusCode int) *http.Response

AssertRedirect makes a request and asserts the redirection happens

func (*Tester) AssertResponse

func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expectedBody string) (*http.Response, string)

AssertResponse request a URI and assert the status code and the body contains a string

func (*Tester) AssertResponseCode

func (tc *Tester) AssertResponseCode(req *http.Request, expectedStatusCode int) *http.Response

AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions

func (*Tester) InitServer

func (tc *Tester) InitServer(rawConfig string, configType string)

InitServer this will configure the server with a configurion of a specific type. The configType must be either "json" or the adapter type.

Jump to

Keyboard shortcuts

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