Help us shape the future of Go! Take the 2026 Go Developer Survey

tcontext

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package tcontext carries block- and runner-scoped test state through context.Context. Shared state belongs to a block; local state belongs to a runner. Lookups provide required-value, nullable-value, and presence-only operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(ctx context.Context, key string) bool

Contains reports presence only.

func Get

func Get(ctx context.Context, key string) (any, bool)

Get returns a value and whether it is present.

func Keys

func Keys(ctx context.Context) []string

Keys returns visible keys in sorted order for diagnostics.

func Remove

func Remove(ctx context.Context, key string)

Remove deletes a key from local scope.

func Resolve

func Resolve(ctx context.Context, key string) (any, error)

Resolve returns a required value or an error. Optional angle brackets around the key are accepted.

func ResolveString

func ResolveString(ctx context.Context, key string) (string, error)

ResolveString resolves a required string value.

func Set

func Set(ctx context.Context, key string, value any) error

Set stores a value in local scope.

func WithLocal

func WithLocal(ctx context.Context, l *Local) context.Context

WithLocal attaches runner-scoped state to a context. Called once per runner.

func WithShared

func WithShared(ctx context.Context, s *Shared) context.Context

WithShared attaches block-scoped state to a context. Called once per block at boot.

Types

type Local

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

Local is runner-scoped state shared by scenarios in that runner.

func LocalOf

func LocalOf(ctx context.Context) (*Local, bool)

LocalOf returns the runner-scoped state carried by a context.

func NewLocal

func NewLocal(runner string) *Local

NewLocal returns local state for a runner.

func (*Local) Append

func (l *Local) Append(key string, value any)

Append adds to a named list, for accumulating created-resource ids.

func (*Local) ClearList

func (l *Local) ClearList(key string)

ClearList empties a named list, for a sweep that has finished with it.

func (*Local) List

func (l *Local) List(key string) []any

List returns a copy of a named list.

func (*Local) ListKeys

func (l *Local) ListKeys() []string

ListKeys returns every non-empty list key, sorted.

func (*Local) Remove

func (l *Local) Remove(key string)

Remove deletes a key.

func (*Local) Runner

func (l *Local) Runner() string

Runner is the owning runner's name.

func (*Local) Set

func (l *Local) Set(key string, value any)

Set stores a scenario-scoped value.

type Shared

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

Shared is block-scoped state populated during boot and read by its runners.

func NewShared

func NewShared(block string) *Shared

NewShared returns shared state for a block.

func SharedOf

func SharedOf(ctx context.Context) (*Shared, bool)

SharedOf returns the block-scoped state carried by a context.

func (*Shared) Block

func (s *Shared) Block() string

Block is the owning block's name, used in diagnostics so a value's origin is traceable.

func (*Shared) Set

func (s *Shared) Set(key string, value any)

Set stores a block-scoped value. Intended for boot; a scenario should be writing to local scope instead.

Jump to

Keyboard shortcuts

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