scriptor

package module
v0.0.0-...-72f3d29 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 5 Imported by: 0

README

scriptor

scriptor is a framework to construct a scripted sequence of actions, such as for testing.

HOW TO USE

1. Create a scene.Scene object

s := scene.New()

2. Add scene.Action objects to scene.Scene

// inline Action
s.Add(scene.ActionFunc(func(ctx context.Context) error {
  // .. do something ...
  return nil
}))

// built-in Action
s.Add(actions.Delay(5*time.Second))

// custom Action object
s.Add(myCustomAction{})

3. Prepare a context.Context object

All transient data in this tool is expected to be passed down along with a context.Context object.

For example, logging is done through a slog.Logger passed down with the context. This means that the context.Context object must be primed with the logger object before the Actions are fired.

To do this, you can manually create a context object using the appropriate injector functions, such as log.InjectContext():

ctx := log.InjectContext(context.Background(), slog.New(....))

Or, to get the default set of values injected, you can use scriptor.DefaultContext():

ctx := scriptor.DefaultContext(context.Background())

The values that need to be injected defer based on the actions that you provide. As of this writing the documentation is lacking, but in the future each component in this module should clearly state which values need to be injected into the context.Context object.

As of this writing it is safest to just use scriptor.DefaultContext() for most everything.

4. Execute the scene.Scene object

Finally, put everything together and execute the scene.

s.Execute(ctx)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultContext

func DefaultContext(ctx context.Context) context.Context

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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