kenginetest

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

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

Default testing values

Functions

func AssertAdapt

func AssertAdapt(t testing.TB, 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.TB, 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 kengine to listening on
	AdminPort int
	// Certificates we expect to be loaded before attempting to run the tests
	Certificates []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 kengine 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.TB) *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