Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidMatchType = errors.New("invalid match type") ErrValueNotANumber = errors.New("value is not a number") )
var ( // ErrValueExceedsRange is returned when the value exceeds the supported range. ErrValueExceedsRange = errors.New("value exceeds supported range") // ErrAorBIsZero is returned when a or b is 0. ErrAorBIsZero = errors.New("a or b is 0") )
var (
ErrAExceedsRangeOfB = errors.New("a must be smaller than b")
)
var (
ErrInvalidPercentageFormat = fmt.Errorf("invalid percentage format")
)
Functions ¶
This section is empty.
Types ¶
type MatchType ¶
type MatchType string
MatchType defines the type of match to be performed.
const ( // MatchTypeLessThan is used to compare the response with the expected value. // If the response is less than the expected value the validation is successful. // If the response is equal or greater than the expected value the validation is not successful. // If the response is not a number the validation is not successful. MatchTypeLessThan MatchType = "lt" // MatchTypeLessThanOrEqual is used to compare the response with the expected value. // If the response is less than or equal to the expected value the validation is successful. // If the response is greater than the expected value the validation is not successful. // If the response is not a number the validation is not successful. MatchTypeLessThanOrEqual MatchType = "lte" // MatchTypeGreaterThan is used to compare the response with the expected value. // If the response is greater than the expected value the validation is successful. // If the response is equal or smaller than the expected value the validation is not successful. // If the response is not a number the validation is not successful. MatchTypeGreaterThan MatchType = "gt" // MatchTypeGreaterThanOrEqual is used to compare the response with the expected value. // If the response is greater than or equal to the expected value the validation is successful. // If the response is smaller than the expected value the validation is not successful. // If the response is not a number the validation is not successful. MatchTypeGreaterThanOrEqual MatchType = "gte" // MatchTypePercentageDeviation is used to compare the response with the expected value. // A percentage offset is calculated from the expected value and the response. // If the percentage offset is smaller than the calculated offset, the validation is successful. // The defined offset is added to the expected value and defines a failure tolerance. MatchTypePercentageDeviation MatchType = "pd" // MatchTypeAbsoluteOffset is used to compare the response with the expected value. // The defined regex is used to match the response. MatchTypeRegex MatchType = "re" // MatchTypeRange is used to compare the response with the expected value. // The defined range is used to match the response. // The value must be in between the range. // If the response is not a number the validation is not successful. MatchTypeRange MatchType = "rg" // MatchTypeEqual is used to compare the response with the expected value. // If the response is equal to the expected value the validation is successful. // If the response is not equal to the expected value the validation is not successful. MatchTypeEqual MatchType = "eq" // MatchTypeNotEqual is used to compare the response with the expected value. // If the response is not equal to the expected value the validation is successful. // If the response is equal to the expected value the validation is not successful. MatchTypeNotEqual MatchType = "neq" // MatchTypeEmpty is used to compare the response with the expected value. // If the response is empty the validation is successful. // If the response is not empty the validation is not successful. MatchTypeEmpty MatchType = "et" // MatchTypeNotEmpty is used to compare the response with the expected value. // If the response is not empty the validation is successful. // If the response is empty the validation is not successful. MatchTypeNotEmpty MatchType = "ne" // MatchTypeContains is used to compare the response with the expected value. // If the response contains the expected value the validation is successful. // If the response does not contain the expected value the validation is not successful. MatchTypeContains MatchType = "ct" )
type Percent ¶
type Percent struct {
// contains filtered or unexported fields
}
Percent represents a custom type that defines a specific allowed value range from 0.0 to 100.0.
func NewPercent ¶
NewPercent returns a new instance of type Percent.
func NewPercentFromFloats ¶
NewPercentFromInts calculates the percent difference between a and b.
func ParsePercentageValueFromString ¶
ParsePercentageValueFromString parses a percentage value from a string and returns the value as type Percent. If the string is not a valid percentage value, an error is returned.
type Report ¶
type Report struct { // Type defines the actual type of A and B // This field has no functional purpose and only exists for discovery. Type string // Index is the index of the byte that differs Index int // Original represents the value of the byte at index in A Original *byte // New defines the value of b passed to the Equal function. New byte }
func ByteDifferent ¶
ByteDifferent returns the difference between a and b.+ If a and b are the same, nil is returned.
type Reports ¶
type Reports []Report
func BytesDifferent ¶
BytesDifferent returns the difference between a and b.
type Validation ¶
type Validation struct { // MatchType defines the type of the validation. // Possible values: // - lt: less than // - lte: less than or equal // - gt: greater than // - gte: greater than or equal // - pd: percentual offset // - re: regex // - rg: range // - eq: equals // - neq: not equals // - ne: not empty // - et: empty // - ct: contains MatchType MatchType // MatchValue defines the value operation. // Must only be set for "percentual offset" and "range" definitions. // Possible values: // - [0-9]-[0-9]: range definition // - [0-9]%: percentual offset // - any: regex MatchValue *string // ExpectedValue defines the expected value. ExpectedValue interface{} }
Validation defines the validation specification to execute a test.
func (Validation) Matches ¶
func (d Validation) Matches(value interface{}) (bool, error)
Matches validates the argument value against the validation specification. If the validation is successful the method returns true as validation and nil as error.