context

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context) []io.Writer

Debug gets a context's Debug writer

func Fixtures

func Fixtures(ctx context.Context) map[string]gdttypes.Fixture

Fixtures gets a context's Fixtures

func New

func New(mods ...ContextModifier) context.Context

New returns a new Context

func Plugins

func Plugins(ctx context.Context) []gdttypes.Plugin

Plugins gets a context's Plugins

func PopTrace added in v1.5.0

func PopTrace(
	ctx context.Context,
) context.Context

PopTrace pops the last name off the debug/trace stack. It is used by plugins to track where in the processing of a test or assertion the plugin is and gets output at the start of a debug.Printf/Println message.

func PriorRun

func PriorRun(ctx context.Context) map[string]interface{}

PriorRun gets a context's prior run data

func PushTrace added in v1.5.0

func PushTrace(
	ctx context.Context,
	name string,
) context.Context

PushTrace pushes a debug/trace name onto the debug/trace stack. It is used by plugins to track where in the processing of a test or assertion the plugin is and gets output at the start of a debug.Printf/Println message.

func RegisterFixture

func RegisterFixture(
	ctx context.Context,
	name string,
	f gdttypes.Fixture,
) context.Context

RegisterFixture registers a named fixtures with the context

func RegisterPlugin

func RegisterPlugin(
	ctx context.Context,
	p gdttypes.Plugin,
) context.Context

RegisterPlugin registers a plugin with the context

func SetDebug

func SetDebug(
	ctx context.Context,
	writers ...io.Writer,
) context.Context

SetDebug sets gdt's debug logging to the supplied `io.Writer`.

The `writers` parameters is optional. If no `io.Writer` objects are supplied, gdt will output debug messages to stdout.

func StorePriorRun

func StorePriorRun(
	ctx context.Context,
	data map[string]interface{},
) context.Context

StorePriorRun saves prior run data in the context. If there is already prior run data cached in the supplied context, the existing data is merged with the supplied data.

func TimedOut

func TimedOut(
	ctx context.Context,
	err error,
) bool

TimedOut evaluates a context and an arbitrary other error and returns true if the context timed out or the error indicates a deadline exceeded or signal was killed.

func Trace added in v1.5.0

func Trace(ctx context.Context) string

Trace gets a context's trace name stack joined together with

func TraceStack added in v1.5.0

func TraceStack(ctx context.Context) []string

TraceStack gets a context's trace name stack

Types

type ContextKey

type ContextKey string

type ContextModifier

type ContextModifier func(context.Context) context.Context

ContextModifier sets some value on the context

func WithDebug

func WithDebug(writers ...io.Writer) ContextModifier

WithDebug informs gdt to output extra debugging information. You can supply zero or more `io.Writer` objects to the function.

If no `io.Writer` objects are supplied, gdt will output debug messages using the `fmt.Printf` function. The `fmt.Printf` function is *unbuffered* however unless you call `go test` with the `-v` argument, `go test` swallows output to stdout and does not display it unless a test fails.

This means that you will only get these debug messages if you call the `go test` tool with the `-v` option (either as `go test -v` or with `go test -v=test2json`.

```go

func TestExample(t *testing.T) {
	   require := require.New(t)
	   fp := filepath.Join("testdata", "example.yaml")
	   f, err := os.Open(fp)
	   require.Nil(err)

	   ctx := gdtcontext.New(gdtcontext.WithDebug())
       s, err := scenario.FromReader(
          f,
          scenario.WithPath(fp),
          scenario.WithContext(ctx),
       )
	   require.Nil(err)
	   require.NotNil(s)

	   err = s.Run(ctx, t)
	   require.Nil(err)
}

```

If you want gdt to log extra debugging information about tests and assertions to a different file or collecting buffer, pass it a context with a debug `io.Writer`:

```go f := ioutil.TempFile("", "mytest*.log") ctx := gdtcontext.New(gdtcontext.WithDebug(f)) ```

```go var b bytes.Buffer w := bufio.NewWriter(&b) ctx := gdtcontext.New(gdtcontext.WithDebug(w)) ```

you can then inspect the debug "log" and do whatever you'd like with it.

func WithFixtures

func WithFixtures(fixtures map[string]gdttypes.Fixture) ContextModifier

WithFixtures sets a context's Fixtures

func WithPlugins

func WithPlugins(plugins []gdttypes.Plugin) ContextModifier

WithPlugins sets a context's Plugins

Jump to

Keyboard shortcuts

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