testcontext

package
v0.0.0-...-d046166 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package testcontext provides logic to extract information from context.

Package testcontext provides logic to extract information from context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

func Log(ctx context.Context, args ...interface{})

Log formats its arguments using default formatting and logs them via ctx.

func Logf

func Logf(ctx context.Context, format string, args ...interface{})

Logf is similar to Log but formats its arguments using fmt.Sprintf.

func OutDir

func OutDir(ctx context.Context) (dir string, ok bool)

OutDir is similar to testing.State.OutDir but takes context instead. It is intended to be used by packages providing support for tests that need to write files.

func ServiceDeps

func ServiceDeps(ctx context.Context) ([]string, bool)

ServiceDeps is similar to testing.State.ServiceDeps but takes context instead. It is intended to be used by packages providing support for tests that want to make sure tests declare proper dependencies.

func SoftwareDeps

func SoftwareDeps(ctx context.Context) ([]string, bool)

SoftwareDeps is similar to testing.State.SoftwareDeps but takes context instead. It is intended to be used by packages providing support for tests that want to make sure tests declare proper dependencies.

func WithCurrentEntity

func WithCurrentEntity(ctx context.Context, ec *CurrentEntity) context.Context

WithCurrentEntity attaches CurrentEntity to context.Context. This function can't be called from user code.

func WithLogger

func WithLogger(ctx context.Context, logger LoggerFunc) context.Context

WithLogger creates a context associated with logger. The returned context can be used to call Log/Logf.

Types

type CurrentEntity

type CurrentEntity struct {
	// OutDir is a directory where the current entity can save output files.
	OutDir string
	// HasSoftwareDeps indicates if software dependencies are available for the
	// current entity. It is true only for tests.
	HasSoftwareDeps bool
	// SoftwareDeps is a list of software dependencies declared in the current entity.
	SoftwareDeps []string
	// ServiceDeps is a list of service dependencies declared in the current entity.
	ServiceDeps []string
}

CurrentEntity contains information about the currently running entity.

Information in this struct is accessible from anywhere via context.Context and testing.Context* functions. Each member should have strong reason to be accessible without testing.*State.

type LoggerFunc

type LoggerFunc = func(msg string)

LoggerFunc is the type of a function to emit log messages.

func Logger

func Logger(ctx context.Context) (LoggerFunc, bool)

Logger extracts a logger from a context.

Jump to

Keyboard shortcuts

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