picker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

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

Examples

Constants

View Source
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

View Source
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 New

func New() *Picker

New initialize a Picker instance.

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

func (picker *Picker) CreateAndPickUUIDS(idNames string) error

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) DisableDebug

func (picker *Picker) DisableDebug()

DisableDebug stops debugging.

func (*Picker) Forget

func (picker *Picker) Forget(key string) error

Forget disposable value.

func (*Picker) ForgetPersistent

func (picker *Picker) ForgetPersistent(key string)

ForgetPersistent forgets persisted value.

func (*Picker) PersistVariable

func (picker *Picker) PersistVariable(key string, value interface{})

PersistVariable adds variable to known values until suite is done or value is manually forgotten.

func (*Picker) PickString

func (picker *Picker) PickString(varName, val string) error

PickString stores provided string as disposable value.

func (*Picker) RegisterTemporaryVariable

func (picker *Picker) RegisterTemporaryVariable(key string, value interface{})

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) Reset

func (picker *Picker) Reset()

Reset picker

func (*Picker) Retrieve

func (picker *Picker) Retrieve(key string) (interface{}, bool)

Retrieve value if exists

func (*Picker) This

func (picker *Picker) This() *internalPicker.Store

This return internal store to pass to other features.

func (*Picker) VerifiesPickedValue

func (picker *Picker) VerifiesPickedValue(pickedKey, matcher, expectedValue string) error

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.

Jump to

Keyboard shortcuts

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