github.com/caddyserver/caddy/v2/caddytest
No package summary is available.
Package
Files: 1. Third party imports: 1. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
Vars
Default testing values
Types
Config
Config store any configuration required to make the tests run
| Field name | Field type | Comment |
|---|---|---|
| AdminPort |
|
Port we expect caddy to listening on |
| Certificates |
|
Certificates we expect to be loaded before attempting to run the tests |
| TestRequestTimeout |
|
TestRequestTimeout is the time to wait for a http request to |
| LoadRequestTimeout |
|
LoadRequestTimeout is the time to wait for the config to be loaded against the caddy server |
Tester
Tester represents an instance of a test client.
| Field name | Field type | Comment |
|---|---|---|
| Client |
|
No comment on field. |
| configLoaded |
|
No comment on field. |
| t |
|
No comment on field. |
| config |
|
No comment on field. |
configLoadError
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| Response |
|
No comment on field. |
Functions
func AssertAdapt
AssertAdapt adapts a config and then tests it against an expected result
func AssertLoadError
AssertLoadError will load a config and expect an error
Uses: strings.Contains.func CompareAdapt
CompareAdapt adapts a config and then compares it against an expected result
Uses: bytes.Buffer, caddyconfig.GetAdapter, difflib.Common, difflib.Diff, difflib.LeftOnly, difflib.RightOnly, fmt.Printf, json.Indent, strings.Split.func CreateTestingTransport
CreateTestingTransport creates a testing transport that forces call dialing connections to happen locally
Uses: context.Context, fmt.Sprintf, http.ProxyFromEnvironment, http.Transport, log.Printf, net.Conn, net.Dialer, strings.Split, time.Second, tls.Config.func NewTester
NewTester will create a new testing client with an attached cookie jar
Uses: cookiejar.New, http.Client.func (*Tester) AssertDeleteResponse
AssertDeleteResponse request a URI and expect a statusCode and body text
Uses: http.NewRequest.func (*Tester) AssertGetResponse
AssertGetResponse GET a URI and expect a statusCode and body text
Uses: http.NewRequest.func (*Tester) AssertPatchResponseBody
AssertPatchResponseBody PATCH to a URI and assert the response code and body
Uses: http.NewRequest.func (*Tester) AssertPostResponseBody
AssertPostResponseBody POST to a URI and assert the response code and body
Uses: http.NewRequest.func (*Tester) AssertPutResponseBody
AssertPutResponseBody PUT to a URI and assert the response code and body
Uses: http.NewRequest.func (*Tester) AssertRedirect
AssertRedirect makes a request and asserts the redirection happens
Uses: http.ErrUseLastResponse, http.Request.func (*Tester) AssertResponse
AssertResponse request a URI and assert the status code and the body contains a string
Uses: io.ReadAll.func (*Tester) AssertResponseCode
AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions
func (*Tester) InitServer
InitServer this will configure the server with a configurion of a specific type. The configType must be either "json" or the adapter type.
func (*Tester) WithDefaultOverrides
WithDefaultOverrides this will override the default test configuration with the provided values.
func (configLoadError) Error
Private functions
func applyHeaders
func getIntegrationDir
func isCaddyAdminRunning
func prependCaddyFilePath
use the convention to replace /[certificatename].[crt|key] with the full path this helps reduce the noise in test configurations and also allow this to run in any path
func timeElapsed
func validateTestPrerequisites
validateTestPrerequisites ensures the certificates are available in the designated path and Caddy sub-process is running.
References: caddycmd.Main, errors.Is, fmt.Errorf, fmt.Sprintf, fs.ErrNotExist, os.Args, os.CreateTemp, os.Remove, os.Stat, time.Second, time.Sleep.func ensureConfigRunning
func initServer
InitServer this will configure the server with a configurion of a specific type. The configType must be either "json" or the adapter type.
References: bytes.Buffer, fmt.Sprintf, http.Client, http.Get, http.NewRequest, io.ReadAll, json.Indent, json.Marshal, json.Unmarshal, strings.NewReader, testing.Short, time.Now.Tests
Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 2. Benchmarks: 0.