test

package
v0.0.0-...-e32ec50 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2016 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package test contains the infrastructure for a proxy tester. Individual tests are found in github.com/seehuhn/jvproxy/tester/lib .

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomString

func RandomString(n int) string

RandomString returns a random string of length `n`, composed of upper- and lower-case letters as well as digits.

Types

type Case

type Case func(Helper, ...interface{})

A Case represents a single unit test for the proxy. The Helper object should be used to generate HTTP requests and responses, and to report the test outcome. Test cases can only be run via Runner.Run(). The optional arguments used in the call to Runner.Run() are passed through to the test case without change.

type Helper

type Helper interface {
	NewRequest(method string) *http.Request
	SendRequestToServer(*http.Request) (http.Header, *http.Request)
	SendResponseToClient(int, *ResponseBodySpec) http.Header

	Log(format string, a ...interface{})
	Fail(format string, a ...interface{})
	Pass(format string, a ...interface{})

	SetInfo(name, RFC string)
}

Helper objects allow test cases to generate HTTP requests and responses, and to report the test outcome. The only way to generate Helper objects is via the Runner.Run() method.

type LogEntry

type LogEntry struct {
	Name     string
	Pass     bool
	Messages []string
}

A LogEntry summarises the results of a single proxy test. The log entry is composed of the proxy test name, a boolean to indicate whether the proxy passed the test, and a list of messages.

func (*LogEntry) Add

func (log *LogEntry) Add(msg string)

Add appends a new message to the log entry.

func (*LogEntry) String

func (log *LogEntry) String() string

String formats the log entry in a multi-line, human readable form.

type ResponseBodySpec

type ResponseBodySpec struct {
	// Seed is used to initialise the random number generator for
	// generating the response.  Small positive integers should be to
	// select which response to generate.
	Seed int64

	// Length specifies the required response body size in bytes.  The
	// length does not include the response header.
	Length int64
}

ResponseBodySpec describes a (synthetic) server response.

func (*ResponseBodySpec) Write

func (task *ResponseBodySpec) Write(w io.Writer) (int64, error)

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

A Runner provides the infrastructure to run a series of tests on a HTTP proxy.

func NewRunner

func NewRunner(proxy *url.URL, log chan<- *LogEntry) *Runner

NewRunner allocates a new test.Runner for testing the given proxy. Test results will be written to the `LogEntry` channel.

func (*Runner) Close

func (run *Runner) Close() error

Close shuts down the test runner and frees all resources associated to the test runner.

func (*Runner) Run

func (run *Runner) Run(test Case, args ...interface{}) (pass bool)

Run executes a single test case. The optional arguments `args` are passed through to the test case.

Jump to

Keyboard shortcuts

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