Documentation
¶
Overview ¶
Package test implements the Benthos service unit testing command.
Index ¶
- func CliCommand(testSuffix string) *cli.Command
- func Generate(path, testSuffix string) error
- func GenerateAll(paths []string, testSuffix string) error
- func OptProcessorsProviderSetLogger(logger log.Modular) func(*ProcessorsProvider)
- func Run(path, testSuffix string, lint bool) bool
- func RunAll(paths []string, testSuffix string, lint bool) bool
- func RunAllWithLogger(paths []string, testSuffix string, lint bool, logger log.Modular) bool
- type Case
- type CaseFailure
- type Condition
- type ConditionsMap
- type ContentEqualsCondition
- type ContentMatchesCondition
- type Definition
- type InputPart
- type MetadataEqualsCondition
- type ProcProvider
- type ProcessorsProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CliCommand ¶
CliCommand is a cli.Command definition for unit testing.
func Generate ¶
Generate executes the generate-tests command for a specified path. The path can either be a config file, a directory, or the special pattern './...'.
func GenerateAll ¶
GenerateAll executes the generate-tests command for a specified paths.
func OptProcessorsProviderSetLogger ¶
func OptProcessorsProviderSetLogger(logger log.Modular) func(*ProcessorsProvider)
OptProcessorsProviderSetLogger sets the logger used by tested components.
func Run ¶
Run executes the test command for a specified path. The path can either be a config file, a config files test definition file, a directory, or the wildcard pattern './...'.
func RunAll ¶
RunAll executes the test command for a slice of paths. The path can either be a config file, a config files test definition file, a directory, or the wildcard pattern './...'.
func RunAllWithLogger ¶
RunAllWithLogger executes the test command for a slice of paths. The path can either be a config file, a config files test definition file, a directory, or the wildcard pattern './...'.
Types ¶
type Case ¶
type Case struct {
Name string `yaml:"name"`
Environment map[string]string `yaml:"environment"`
TargetProcessors string `yaml:"target_processors"`
InputBatch []InputPart `yaml:"input_batch"`
OutputBatches [][]ConditionsMap `yaml:"output_batches"`
// contains filtered or unexported fields
}
Case contains a definition of a single Benthos config test case.
func (*Case) Execute ¶
func (c *Case) Execute(provider ProcProvider) (failures []CaseFailure, err error)
Execute attempts to execute a test case against a Benthos configuration.
type CaseFailure ¶
CaseFailure encapsulates information about a failed test case.
func (CaseFailure) String ¶
func (c CaseFailure) String() string
String returns a string representation of the case failure.
type ConditionsMap ¶
ConditionsMap contains a map of conditions to condition string types.
func (ConditionsMap) CheckAll ¶
func (c ConditionsMap) CheckAll(part types.Part) (errs []error)
CheckAll checks all conditions against a message part. Conditions are executed in alphabetical order.
func (*ConditionsMap) UnmarshalYAML ¶
func (c *ConditionsMap) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML extracts a ConditionsMap from a YAML node.
type ContentEqualsCondition ¶
type ContentEqualsCondition string
ContentEqualsCondition is a string condition that tests the string against the contents of a message.
type ContentMatchesCondition ¶
type ContentMatchesCondition string
ContentMatchesCondition is a string condition that tests parses the string as a regular expression and tests that regular expression against the contents of a message.
type Definition ¶
Definition of a group of tests for a Benthos config file.
func ExampleDefinition ¶
func ExampleDefinition() Definition
ExampleDefinition returns a Definition containing an example case.
func (Definition) Execute ¶
func (d Definition) Execute(filepath string) ([]CaseFailure, error)
Execute attempts to run a test definition on a target config file. Returns an array of test failures or an error.
func (Definition) ExecuteWithLogger ¶
func (d Definition) ExecuteWithLogger(filepath string, logger log.Modular) ([]CaseFailure, error)
ExecuteWithLogger attempts to run a test definition on a target config file, with a logger. Returns an array of test failures or an error.
type InputPart ¶
type InputPart struct {
Content string `yaml:"content"`
Metadata map[string]string `yaml:"metadata"`
}
InputPart defines an input part for a test case.
type MetadataEqualsCondition ¶
MetadataEqualsCondition checks whether a metadata keys contents matches a value.
type ProcProvider ¶
type ProcProvider interface {
Provide(jsonPtr string, environment map[string]string) ([]types.Processor, error)
}
ProcProvider returns compiled processors extracted from a Benthos config using a JSON Pointer.
type ProcessorsProvider ¶
type ProcessorsProvider struct {
// contains filtered or unexported fields
}
ProcessorsProvider consumes a Benthos config and, given a JSON Pointer, extracts and constructs the target processors from the config file.
func NewProcessorsProvider ¶
func NewProcessorsProvider(targetPath string, opts ...func(*ProcessorsProvider)) *ProcessorsProvider
NewProcessorsProvider returns a new processors provider aimed at a filepath.
func (*ProcessorsProvider) Provide ¶
func (p *ProcessorsProvider) Provide(jsonPtr string, environment map[string]string) ([]types.Processor, error)
Provide attempts to extract an array of processors from a Benthos config. If the JSON Pointer targets a single processor config it will be constructed and returned as an array of one element.