cfgtest

package
v0.0.0-...-ad46a6f Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions parser.Actions

Actions represent the actions applied by a filter.

func (Actions) Equal

func (a Actions) Equal(a2 Actions) bool

Equal returns true if the given actions are equivalent to this object.

type FailedTest

type FailedTest struct {
	ID     int
	Name   string
	Errors []error
}

FailedTest includes all the errors of a failed test.

func (FailedTest) String

func (t FailedTest) String() string

type Result

type Result struct {
	OK       bool
	NumTests int
	Failed   []FailedTest
}

Result represents the result of a series of tests.

func (Result) String

func (r Result) String() string

type Rule

type Rule struct {
	Eval    RuleEvaluator
	Actions Actions
}

Rule represents a filter that can evaluate whether messages apply to it.

type RuleEvaluator

type RuleEvaluator interface {
	// Match returns true if the given message matches the filter criteria.
	Match(msg cfg.Message) bool
}

RuleEvaluator represents a filter criteria able to evaluate if an email matches its definition.

func NewEvaluator

func NewEvaluator(criteria parser.CriteriaAST) (RuleEvaluator, error)

NewEvaluator creates a RuleEvaluator starting from a parser criteria.

type Rules

type Rules []Rule

Rules is a set of rules.

func NewFromParserRules

func NewFromParserRules(rs []parser.Rule) (Rules, error)

NewFromParserRules translates parser Rules into test Rules.

This function is best effort. Every criteria that is not convertible is going to be ignored and an error is returned in its place. The resulting rules will contain only the valid rules.

func (Rules) ExecTest

func (rs Rules) ExecTest(t v1alpha3.Test) []error

ExecTest evaluates the rules on all the messages of the given test.

If the rules apply as expected by the test, no error is returned.

func (Rules) ExecTests

func (rs Rules) ExecTests(ts []v1alpha3.Test) Result

ExecTests evaluates all the rules against the given tests.

The evaluation stops at the first failing test.

func (Rules) MatchingActions

func (rs Rules) MatchingActions(msg v1alpha3.Message) (Actions, error)

MatchingActions returns the actions that would be applied by the rules if the given message arrived.

An error can be returned if multiple incompatible actions would be applied. Note that in Gmail this wouldn't be an error, but a nondeterministic action would be applied. Since this situation is most likely a mistake by the user, we treat it as an error.

Jump to

Keyboard shortcuts

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