testcontext

package
v0.0.0-...-b5d9cbe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 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 EnsurePrivateAttr

func EnsurePrivateAttr(ctx context.Context, name string)

EnsurePrivateAttr ensures the current entity declares a privateAttr in its metadata. Otherwise it will panic.

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 PrivateAttr

func PrivateAttr(ctx context.Context) (privateAttr []string, ok bool)

PrivateAttr returns the private attributes of current entity.

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 WithPrivateData

func WithPrivateData(ctx context.Context, pd PrivateData) context.Context

WithPrivateData attaches PrivateData to context.Context. This function must not be exposed to user code.

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.
	// TODO(b/229939530): Will add support for multi-DUT dependency in future.
	SoftwareDeps []string
	// ServiceDeps is a list of service dependencies declared in the current entity.
	ServiceDeps []string
	// PrivateAttr is a list of private attributes declared in the current entity.
	PrivateAttr []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 PrivateData

type PrivateData struct {
	// WaitUntilReady carries the value of -waituntilready flag.
	WaitUntilReady bool
	// WaitUntilReadyTimeout carries the value of -waituntilreadytimeout flag.
	WaitUntilReadyTimeout time.Duration
}

PrivateData contains information private to the framework.

func PrivateDataFromContext

func PrivateDataFromContext(ctx context.Context) (pd PrivateData, ok bool)

PrivateDataFromContext extracts PrivateData from a context.Context. This function must not be exposed to user code.

Jump to

Keyboard shortcuts

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