unittest

package
v0.0.0-...-684fe44 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Overview

A simple package for dealing with logging module output during the unit testing cycle.

Example
// Setup
buffer := SetupBuffer()
defer buffer.DumpToStdout()

// Unit tests go here.

// Clear the buffer so nothing ends up being printed.
buffer.Clear()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogBuffer

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

This will be used as a Output object as a logging destination. It is configured to capture all logs and store them in memory, flushing them only if the unit test fails.

func SetupBuffer

func SetupBuffer() *LogBuffer

Sets up everything needed to unit test against a LogBuffer object. The returned object will use numerical counters rather than dates in order to make the output predictable.

func (*LogBuffer) Clear

func (l *LogBuffer) Clear()

Clears the list of lines in the buffer.

func (*LogBuffer) DumpToFile

func (l *LogBuffer) DumpToFile(path string)

func (*LogBuffer) DumpToStdout

func (l *LogBuffer) DumpToStdout()

Dumps all the lines in the buffer to stdout.

func (*LogBuffer) FinishTest

func (l *LogBuffer) FinishTest(t Logger)

Dumps the logs in the log buffer if the test failed, otherwise clears them for the next test.

func (*LogBuffer) Flush

func (l *LogBuffer) Flush() error

Required to implement the Output interface.

func (*LogBuffer) Lines

func (l *LogBuffer) Lines() []string

Gets all received lines from the tracker.

func (*LogBuffer) NewLines

func (l *LogBuffer) NewLines() []string

func (*LogBuffer) Write

func (l *LogBuffer) Write(ld *logray.LineData) error

Tracker implementation of io.Writer to let this object receive logs.

type Logger

type Logger interface {
	Failed() bool
}

Interface that matches both testing.T and testing.B.

Jump to

Keyboard shortcuts

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