Documentation
¶
Index ¶
- func Debug(ctx context.Context) []io.Writer
- func Fixtures(ctx context.Context) map[string]api.Fixture
- func New(mods ...ContextModifier) context.Context
- func Plugins(ctx context.Context) []api.Plugin
- func PopTrace(ctx context.Context) context.Context
- func PriorRun(ctx context.Context) map[string]interface{}
- func PushTrace(ctx context.Context, name string) context.Context
- func RegisterFixture(ctx context.Context, name string, f api.Fixture) context.Context
- func RegisterPlugin(ctx context.Context, p api.Plugin) context.Context
- func SetDebug(ctx context.Context, writers ...io.Writer) context.Context
- func StorePriorRun(ctx context.Context, data map[string]interface{}) context.Context
- func TimedOut(ctx context.Context, err error) bool
- func Trace(ctx context.Context) string
- func TraceStack(ctx context.Context) []string
- type ContextKey
- type ContextModifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PopTrace ¶ added in v1.5.0
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 PushTrace ¶ added in v1.5.0
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 ¶
RegisterFixture registers a named fixtures with the context
func RegisterPlugin ¶
RegisterPlugin registers a plugin with the context
func SetDebug ¶
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 ¶
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 ¶
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 TraceStack ¶ added in v1.5.0
TraceStack gets a context's trace name stack
Types ¶
type ContextKey ¶
type ContextKey string
type ContextModifier ¶
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]api.Fixture) ContextModifier
WithFixtures sets a context's Fixtures
func WithPlugins ¶
func WithPlugins(plugins []api.Plugin) ContextModifier
WithPlugins sets a context's Plugins