cuetest

package
v0.0.0-...-852726b Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DebugEvent         = GenerateEvent(cue.DEBUG, ctx, "debug event", nil, 3)
	DebugEventNoFrames = GenerateEvent(cue.DEBUG, ctx, "debug event", nil, 0)
	InfoEvent          = GenerateEvent(cue.INFO, ctx, "info event", nil, 3)
	InfoEventNoFrames  = GenerateEvent(cue.INFO, ctx, "info event", nil, 0)
	WarnEvent          = GenerateEvent(cue.WARN, ctx, "warn event", nil, 3)
	WarnEventNoFrames  = GenerateEvent(cue.WARN, ctx, "warn event", nil, 0)
	ErrorEvent         = GenerateEvent(cue.ERROR, ctx, "error event", errors.New("error message"), 3)
	ErrorEventNoFrames = GenerateEvent(cue.ERROR, ctx, "error event", errors.New("error message"), 0)
	FatalEvent         = GenerateEvent(cue.FATAL, ctx, "fatal event", errors.New("fatal message"), 3)
	FatalEventNoFrames = GenerateEvent(cue.FATAL, ctx, "fatal event", errors.New("fatal message"), 0)
)

Test events at all cue event levels. The *Event instances have 3 frames in there Frames field while the *EventNoFrames instances have 0.

Functions

func CloseCollector

func CloseCollector(c cue.Collector)

CloseCollector calls c.Close() if c implements the io.Closer interface. If c.Close() doesn't return within 5 seconds, CloseCollector panics.

func GenerateEvent

func GenerateEvent(level cue.Level, context cue.Context, message string, err error, frames int) *cue.Event

GenerateEvent returns a new event for the given parameters. The frames parameter determines how many frames to attach to the Frames field. The generated frames follow a naming pattern based on their index. The time used for the generated event is the same time used by the time package to represent time formats.

func NestedCompare

func NestedCompare(t *testing.T, input map[string]interface{}, expected map[string]interface{})

NestedCompare treats input and expected as nested map[string]interface{} and performs a deep comparison between them. If the maps aren't equal, it calls t.Errorf with a pretty-printed comparison.

func NestedDelete

func NestedDelete(j map[string]interface{}, path ...string)

NestedDelete treats j as a nested map[string]interface{} and attempts to delete the value specified by the path. If does nothing if the path doesn't correspond to a valid key.

func NestedFetch

func NestedFetch(j map[string]interface{}, path ...string) interface{}

NestedFetch treats j as a nested map[string]interface{} and attempts to retrieve the value specified by path. It returns "!(MISSING)" if the value is missing, or "!(NOTAKEY)" if part of the path exists but terminates early at a value that isn't a key.

func NewFailingHTTPTransport

func NewFailingHTTPTransport(succeedAfter int) http.RoundTripper

NewFailingHTTPTransport returns a http.RoundTripper that fails requests until succeedAfter count have been submitted. Afterwards, it passes requests to http.DefaultTransport.

func ParseRequestJSON

func ParseRequestJSON(req *http.Request) map[string]interface{}

ParseRequestJSON parses the request body as json, returning a nested map[string]interface{} of the decoded contents. If the content isn't well-formed, ParseRequestJSON panics.

func ParseStringJSON

func ParseStringJSON(jstr string) map[string]interface{}

ParseStringJSON parses the input jstr as json, returning a nested map[string]interface{} of the decoded contents. If the content isn't well-formed ParseStringJSON panics.

func ResetCue

func ResetCue()

ResetCue calls cue.Close(time.Minute). If that returns a non-nil result, ResetCue panics.

Types

type CapturingCollector

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

CapturingCollector captures events that are sent to its Collect method.

func NewCapturingCollector

func NewCapturingCollector() *CapturingCollector

NewCapturingCollector returns a new CapturingCollector instance.

func (*CapturingCollector) Captured

func (c *CapturingCollector) Captured() []*cue.Event

Captured returns a slice of captured events.

func (*CapturingCollector) Collect

func (c *CapturingCollector) Collect(event *cue.Event) error

Collect captures the input event for later inspection.

func (*CapturingCollector) String

func (c *CapturingCollector) String() string

String returns a string representation of the CapturingCollector.

func (*CapturingCollector) WaitCaptured

func (c *CapturingCollector) WaitCaptured(count int, maxWait time.Duration)

WaitCaptured waits for count events to be captured. If count events aren't captured within maxWait time, it panics.

type HTTPRequestRecorder

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

HTTPRequestRecorder implements http.RoundTripper, capturing all requests that are sent to it.

func NewHTTPRequestRecorder

func NewHTTPRequestRecorder() *HTTPRequestRecorder

NewHTTPRequestRecorder returns a new HTTPRequestRecorder instance.

func (*HTTPRequestRecorder) Requests

func (rr *HTTPRequestRecorder) Requests() []*http.Request

Requests returns a slice of the requests captured by the recorder.

func (*HTTPRequestRecorder) ServeHTTP

func (rr *HTTPRequestRecorder) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is implemented to satisfy the http.RoundTripper interface.

type NetRecorder

type NetRecorder interface {
	// Address returns the address string for the recorder.
	Address() string

	// Contents returns the bytes that have been sent to the recorder.
	Contents() []byte

	// CheckByteContents checks if the bytes captured by the recorder match the
	// given expectation.  If not, t.Errorf is called with a comparison.
	CheckByteContents(t *testing.T, expectation []byte)

	// CheckStringContents checks if the bytes captured by the recorder match
	// the given string expectation.  If not, t.Errorf is called with a
	// comparison.
	CheckStringContents(t *testing.T, expectation string)

	// Start starts the recorder.
	Start()

	// Close stops the recorder and terminates any active connections.
	Close() error

	// Done returns a channel that blocks until the recorder is finished.
	Done() <-chan struct{}

	// Err returns the first error encountered by the recorder, if any.
	Err() error
}

NetRecorder is an interface representing a network listener/recorder. The recorder stores all content sent to it. Recorders are created in an unstarted state and must be explicitly started via the Start() method and explicitly stopped via the Close() method once finished.

func NewTCPRecorder

func NewTCPRecorder() NetRecorder

NewTCPRecorder returns a NetRecorder that listens for TCP connections.

func NewTLSRecorder

func NewTLSRecorder() NetRecorder

NewTLSRecorder returns a NetRecorder that listens for TCP connections using TLS transport encryption.

Jump to

Keyboard shortcuts

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