scriptor
is a framework to construct a scripted sequence of actions, such as for testing.
s := scene.New()
// 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{})
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 Action
s 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.
Finally, put everything together and execute the scene.
s.Execute(ctx)