tko

package
v0.0.0-...-c42b739 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

README

TKO - test keryx output

tko is a simple query language for keryx streams. It is used by the smoke tests for instance for specifying expected outputs.

Conditions

tko supports a variety of condition types at the top level. Each of these condition types have different expected query syntax.

has_message - any message in the transaction matches

This would return true for any transaction that has a message for the users table that is missing fields data:

'{"has_message":{"rel":"users", "missing_fields":true}}'

Fields of the message that can be queried are: type, db, ns, rel, ctid, prev_ctid. missing_fields is a boolean that will look for a messages with no field data if true, or with any field data if false. waits is a boolean that if set to true will match against the populate_wait field. fields_match allow you to check the specific fields of messages.

This will match any message with field foo == bar and goo == boo:

'{"has_message":{"fields_match":{"foo":"bar", "goo":"boo"}}}'
transaction_is - transaction has specific properties

This condition returns true if the transaction matches its query syntax.

To check a specific transaction id:

'{"transaction_is":{"xid":78}}'

To check for big transactions:

'{"transaction_is":{"big":true}}'
transactions_that - stateful query that returns true once all conditions are matched across many transactions

This would return true once it saw transactions that were for for table users and a transaction that is big:

'{"transactions_that":[{"has_message":{"rel":"users"}}, {"transaction_is":{"big":true}}]}'

Note: One transaction that was big and for users would count.

not - inverts the condition

This will return true on any transaction that does not have a users message:

'{"not":{"has_message":{"rel":"users"}}}'
any_of - ors the conditions

This will return on any transaction that has a users message or a dogs message:

'{"any_of":[{"has_message":{"rel":"users"}}, {"has_message":{"rel":"dogs"}}]}'
all_of - ands the conditions

This will return on any transaction that hasb bot a users message and a dogs message:

'{"any_of":[{"has_message":{"rel":"users"}}, {"has_message":{"rel":"dogs"}}]}'
always - always true

This is used when you want to return true as part of the query language.

'{"always":{}}'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllOf

type AllOf []Condition

AllOf will return true if all of its underlying Conditions return true. Logical And.

func AllOfThese

func AllOfThese(definitions []ConditionDefinition) (allOf AllOf, err error)

AllOfThese creates an AllOf Condition from a list of definitions

func (AllOf) Check

func (c AllOf) Check(txn *message.Transaction) bool

Check will return true if all of the underlying conditions return true.

type Always

type Always struct{}

Always will always return true

func (*Always) Check

func (c *Always) Check(txn *message.Transaction) bool

Check will always return true for an always condition.

type AnyOf

type AnyOf []Condition

AnyOf will return true if any of its underlying Conditions return true. Logical Or.

func AnyOfThese

func AnyOfThese(definitions []ConditionDefinition) (anyOf AnyOf, err error)

AnyOfThese creates an AnyOf from other definitions

func (AnyOf) Check

func (c AnyOf) Check(txn *message.Transaction) bool

Check will return true if any of the underlying conditions return true.

type Condition

type Condition interface {
	Check(*message.Transaction) bool
	// contains filtered or unexported methods
}

Condition models the an assertion that can be applied to a Transaction

func GetConditionFromArgsOrStdIn

func GetConditionFromArgsOrStdIn(ctx *cli.Context) (Condition, error)

GetConditionFromArgsOrStdIn will attempt to parse the first argument as a tko condition. If no args are available it will instead try to parse stdin

func ReadConditionFromJSON

func ReadConditionFromJSON(jsonStr string) (Condition, error)

ReadConditionFromJSON parses a json string into a condition

type ConditionDefinition

type ConditionDefinition struct {
	Always           *Always                `json:"always"`
	IsTransaction    *TransactionIs         `json:"transaction_is"`
	TransactionsThat *[]ConditionDefinition `json:"transactions_that"`
	HasMessage       *HasMessage            `json:"has_message"`
	Not              *ConditionDefinition   `json:"not"`
	AnyOf            *[]ConditionDefinition `json:"any_of"`
	AllOf            *[]ConditionDefinition `json:"all_of"`
}

ConditionDefinition wraps around the condition and allows it to be parsed generically. Only 1 of the fields will be returned if multiple exist

type HasMessage

type HasMessage struct {
	Type          *message.Type          `json:"type"`
	DatabaseName  *string                `json:"db"`
	Namespace     *string                `json:"ns"`
	Relation      *string                `json:"rel"`
	TupleID       *string                `json:"ctid"`
	PrevTupleID   *string                `json:"prev_ctid"`
	FieldsMatch   map[string]interface{} `json:"fields_match"`
	MissingFields *bool                  `json:"missing_fields"`
	Waits         *bool                  `json:"waits"`
}

HasMessage will match if any message in the transaction matches the provided message.

func (*HasMessage) Check

func (c *HasMessage) Check(txn *message.Transaction) bool

Check will return true if all of the defined conditions for HasMessage match.

type Not

type Not struct {
	// contains filtered or unexported fields
}

Not will return the inverse of the underlying condition.

func (*Not) Check

func (c *Not) Check(txn *message.Transaction) bool

Check will return the opposite of the underlying condition for the not condition.

type TransactionIs

type TransactionIs struct {
	TransactionID  *uint32 `json:"xid"`
	BigTransaction *bool   `json:"big"`
}

TransactionIs will match a specific TransactionID

func (*TransactionIs) Check

func (c *TransactionIs) Check(txn *message.Transaction) bool

Check will return true if the transaction id matches for TransactionIDMatches conditions.

type TransactionsThat

type TransactionsThat struct {
	// contains filtered or unexported fields
}

TransactionsThat will return false until a transaction is found for every conditions. It is a stateful transaction filter.

func TransactionsOfThese

func TransactionsOfThese(definitions []ConditionDefinition) (transactionsThat *TransactionsThat, err error)

TransactionsOfThese creates an TransactionsThat from other definitions

func (*TransactionsThat) Check

func (t *TransactionsThat) Check(txn *message.Transaction) bool

Check will return true if any of the underlying conditions return true.

Jump to

Keyboard shortcuts

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