Documentation
¶
Overview ¶
package picker provides simple function to create steps
Example ¶
var scenarioCtx *godog.ScenarioContext pickerInstance := picker.New() // Create a step registering variables that will be reset on picker.Cancel scenarioCtx.Step("^I wish to pick key ([a-z]*) as value .*$", func(key, value string) error { pickerInstance.RegisterTemporaryVariable(key, value) return nil }) // Create a step to retrieve a picked value. scenarioCtx.Step("^I wish to use value [a-z]*$", func(key string) error { value, ok := pickerInstance.Retrieve(key) if !ok { return picker.ErrNotPicked } fmt.Println(value) // do something with value. return nil }) // Ensure picked value matches expected one. scenarioCtx.Step("^I wish to ensure value [a-z]* (equals|matches) .*$", pickerInstance.VerifiesPickedValue) // Ensure some picked values matches expected data (using gherkin data table) scenarioCtx.Step("^I wish to ensure values are correct:$", pickerInstance.VerifiesPickedValues) // Registering persistent information before scenario. Those key will not be reset. To forget them, // call picker.ForgetPersistent scenarioCtx.BeforeScenario(func(sc *godog.Scenario) { pickerInstance.PersistVariable("test", true) pickerInstance.RegisterVariables(map[string]interface{}{"name": "sample", "simple": true}, picker.Persistent) }) // Setup reset after steps (should not be a good idea in a normal use case ^^) scenarioCtx.AfterStep(func(st *godog.Step, err error) { pickerInstance.Reset() }) // Forget test name after scenario scenarioCtx.AfterScenario(func(sc *godog.Scenario, err error) { pickerInstance.Forget("name") })
Output:
Index ¶
- Constants
- Variables
- type Picker
- func (picker *Picker) BeforeStepReplacer(step *messages.Pickle_PickleStep)
- func (picker *Picker) CreateAndPickUUIDS(idNames string) error
- func (picker *Picker) Debug()
- func (picker *Picker) DisableDebug()
- func (picker *Picker) Forget(key string) error
- func (picker *Picker) ForgetPersistent(key string)
- func (picker *Picker) PersistVariable(key string, value interface{})
- func (picker *Picker) PickString(varName, val string) error
- func (picker *Picker) RegisterTemporaryVariable(key string, value interface{})
- func (picker *Picker) RegisterVariables(variables map[string]interface{}, scope internalPicker.DataScope)
- func (picker *Picker) Reset()
- func (picker *Picker) Retrieve(key string) (interface{}, bool)
- func (picker *Picker) This() *internalPicker.Store
- func (picker *Picker) VerifiesPickedValue(pickedKey, matcher, expectedValue string) error
- func (picker *Picker) VerifiesPickedValues(assertions *messages.PickleStepArgument_PickleTable) error
Examples ¶
Constants ¶
const ( // Persistent exposes internal picker.PersistentValue to // indicate values should be stored in the Persistent scope. Persistent = internalPicker.PersistentValue // Disposable exposes internal picker.DisposableValue to // indicate values should be stored in the Disposable scope. Disposable = internalPicker.DisposableValue )
Variables ¶
var ErrNotPicked = errors.New("unpicked value")
Functions ¶
This section is empty.
Types ¶
type Picker ¶
type Picker struct {
// contains filtered or unexported fields
}
Picker is a key/value store to manage variable injection through godog steps.
func (*Picker) BeforeStepReplacer ¶
func (picker *Picker) BeforeStepReplacer(step *messages.Pickle_PickleStep)
BeforeStepReplacer provides a replacer function to use in godog BeforeStep hook.
func (*Picker) CreateAndPickUUIDS ¶
CreateAndPickUUIDS generates and stores an UUID for each provided keys (`, ` separated) as disposable value. It will be forgotten on reset.
func (*Picker) Debug ¶
func (picker *Picker) Debug()
Debug start debug logs for picker. It will be removed when calling Reset.
func (*Picker) ForgetPersistent ¶
ForgetPersistent forgets persisted value.
func (*Picker) PersistVariable ¶
PersistVariable adds variable to known values until suite is done or value is manually forgotten.
func (*Picker) PickString ¶
PickString stores provided string as disposable value.
func (*Picker) RegisterTemporaryVariable ¶
RegisterTemporaryVariable adds variable to known values up to instance reset.
func (*Picker) RegisterVariables ¶
func (picker *Picker) RegisterVariables(variables map[string]interface{}, scope internalPicker.DataScope)
RegisterVariables adds variables to known values using provided scopes.
func (*Picker) This ¶
func (picker *Picker) This() *internalPicker.Store
This return internal store to pass to other features.
func (*Picker) VerifiesPickedValue ¶
VerifiesPickedValues asserts variable value matches expected condition.
func (*Picker) VerifiesPickedValues ¶
func (picker *Picker) VerifiesPickedValues(assertions *messages.PickleStepArgument_PickleTable) error
VerifiesPickedValues asserts variables values matches expected conditions.