subcommandstest

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package subcommandstest includes tools to help with concurrent testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLogOutput

func DisableLogOutput() *bytes.Buffer

DisableLogOutput redirect log's default logger to a buffer and returns it. This function should be called in an init function.

func PrintIf

func PrintIf(b []byte, name string)

PrintIf trims the whitespace around a string encoded as []byte and prints it only if not empty.

Types

type Application

type Application interface {
	subcommands.Application
	GetLog() *log.Logger
}

Application supports all of subcommands.Application and adds GetLog() for testing purposes.

type ApplicationMock

type ApplicationMock struct {
	subcommands.Application
	*TB
}

ApplicationMock wrap both an Application and a TB. ApplicationMock implements GetOut and GetErr and adds GetLog(). GetLog() is implemented by TB.

func MakeAppMock

func MakeAppMock(t *testing.T, a subcommands.Application) *ApplicationMock

MakeAppMock returns an initialized ApplicationMock.

func (*ApplicationMock) GetErr

func (a *ApplicationMock) GetErr() io.Writer

GetErr implements subcommands.Application.

func (*ApplicationMock) GetOut

func (a *ApplicationMock) GetOut() io.Writer

GetOut implements subcommands.Application.

type TB

type TB struct {
	*testing.T
	// contains filtered or unexported fields
}

TB wraps a testing.T object and adds functionality specific to command_support.

BUG: testing.TB is now a thing, so this struct should likely be renamed to reduce confusion?

func MakeTB

func MakeTB(t *testing.T) *TB

MakeTB returns a fully initialized TB instance.

func (*TB) CheckBuffer

func (t *TB) CheckBuffer(out, err bool)

CheckBuffer asserts the content of os.Stdout and os.Stderr mocks.

func (*TB) CheckOut

func (t *TB) CheckOut(expected string)

CheckOut asserts that what was printed out Application.GetOut() matches what is expected. TODO(maruel): It doesn't matches the use case where the match must be fuzzy, for example when non-deterministic data is included in the output.

func (*TB) GetLog

func (t *TB) GetLog() *log.Logger

GetLog implements Application.

func (*TB) Verbose

func (t *TB) Verbose()

Verbose sets the current context as verbose. It immediately prints out all logs generated for this specific test case up to now and redirects the log to os.Stderr so the following log is directly output to the console.

Jump to

Keyboard shortcuts

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