context

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 7 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 PriorRun

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

PriorRun gets a context's prior run data

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 using the `testing.T.Log[f]()` function. 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`.

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.

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 `testing.T.Log[f]()` function. 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