Skip to content

Framework to construct a scripted sequence of actions, such as for testing

License

Notifications You must be signed in to change notification settings

lestrrat-go/scriptor

Repository files navigation

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)

About

Framework to construct a scripted sequence of actions, such as for testing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages