script

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dereference

func Dereference(v string) (bool, string, string)

Dereference checks if v is a reference to another operation and returns a ParameterAccess function for it.

func Load

func Load(path string, log contract.Logger) contract.Script

Load loads a script file.

func NoGraph

func NoGraph(err error, log contract.Logger) gcontract.Graph

NoGraph creates a new NullGraph instance.

func NoScript

func NoScript(err error, log contract.Logger) contract.Script

NoScript creates a new NullScript instance.

Types

type ExecutionGraph

type ExecutionGraph struct {
	contract.EntityTrait
	*gog.DGraph
}

ExecutionGraph is a graph representing interdependencies between operations.

func NewExecutionGraph

func NewExecutionGraph(log contract.Logger) *ExecutionGraph

NewExecutionGraph creates a new OperationGraph instance.

type ExecutionNode

type ExecutionNode struct {
	Operation  contract.Operation
	OpRefID    string
	Data       contract.OperationData
	Mutex      sync.Mutex
	Result     *contract.OperationResult
	Use        *OperationDataUse
	Expect     *OperationDataUse
	ExpectBody *params.BodyParameters
}

ExecutionNode represents a single operation in the script execution graph. It contains a pointer to an operation and keeps an OperationData instance where operation parameters are stored. Those later get loaded into an Operation's own Data() instance.

func NewExecutionNode

func NewExecutionNode(op contract.Operation, opRefID string, opRef *OperationRef, log contract.Logger) *ExecutionNode

NewExecutionNode creates a new ExecutionNode instance.

func (*ExecutionNode) ID

func (node *ExecutionNode) ID() gcontract.NodeID

ID returns a uniqe operation node ID.

func (*ExecutionNode) Lock

func (node *ExecutionNode) Lock()

Lock locks the node to prevent parallel executions.

func (*ExecutionNode) Unlock

func (node *ExecutionNode) Unlock()

Unlock unlocks the node.

type Executor

type Executor struct {
	contract.EntityTrait
}

Executor executes an ExecutionGraph that comes from a script.

func NewExecutor

func NewExecutor(log contract.Logger) *Executor

NewExecutor creates a new Executor instance.

func (Executor) Execute

func (ex Executor) Execute(graph gcontract.Graph)

Execute executes.

func (Executor) Walk

func (ex Executor) Walk(
	graph gcontract.Graph,
	n *ExecutionNode,
	nwg *sync.WaitGroup,
	nresults *contract.OperationResults,
)

Walk walks the execution graph and executes operations.

type NullGraph

type NullGraph struct {
	errors.NullObjectPrototype
}

NullGraph is used whenever we can't have a real execution graph from a script. Reports the contained error on every method call.

func (NullGraph) AddEdge

func (g NullGraph) AddEdge(v1 gcontract.NodeID, v2 gcontract.NodeID)

AddEdge reports an error.

func (NullGraph) AddNode

func (g NullGraph) AddNode(n gcontract.Node)

AddNode reports an error.

func (NullGraph) AdjacentNodes

func (g NullGraph) AdjacentNodes(nID gcontract.NodeID) gcontract.Nodes

AdjacentNodes reports an error.

func (NullGraph) BFS

BFS reports an error.

func (NullGraph) DFS

DFS reports an error.

func (*NullGraph) Len

func (g *NullGraph) Len() uint

Len reports an error.

func (NullGraph) Node

func (g NullGraph) Node(nID gcontract.NodeID) gcontract.Node

Node reports an error.

func (NullGraph) Nodes

func (g NullGraph) Nodes() gcontract.Nodes

Nodes reports an error.

func (NullGraph) RBFS

RBFS reports an error.

func (NullGraph) RDFS

RDFS reports an error.

func (NullGraph) UpstreamNodes

func (g NullGraph) UpstreamNodes(nID gcontract.NodeID) gcontract.Nodes

UpstreamNodes reports an error.

type NullScript

type NullScript struct {
	errors.NullObjectPrototype
}

NullScript is used whenever we can't have a real one. Reports the contained error on every method call.

func (*NullScript) GetExecutionGraph

func (s *NullScript) GetExecutionGraph() gcontract.Graph

GetExecutionGraph reports an error.

type OperationDataExpect

type OperationDataExpect struct {
	Body    OperationDataMap `yaml:"body"`
	Headers OperationDataMap `yaml:"headers"`
	CT      string           `yaml:"CT"`
	Status  int64            `yaml:"status"`
}

OperationDataExpect corresponds to the 'expect' block of the OperationRef in a script file.

type OperationDataMap

type OperationDataMap map[string]string

OperationDataMap is a map of parameters for an OperationRef.

func (OperationDataMap) Iterate

Iterate creates an iterable channel.

type OperationDataUse

type OperationDataUse struct {
	Path     OperationDataMap `yaml:"path"`
	Body     OperationDataMap `yaml:"body"`
	Query    OperationDataMap `yaml:"query"`
	Headers  OperationDataMap `yaml:"headers"`
	Security OperationDataMap `yaml:"security"`
	CT       string           `yaml:"CT"`
	Status   int64            `yaml:"status"`
}

OperationDataUse corresponds to the 'use' block of the OperationRef in a script file.

type OperationRef

type OperationRef struct {
	OperationID string           `yaml:"operationId"`
	After       string           `yaml:"after"`
	Use         OperationDataUse `yaml:"use"`
	Expect      OperationDataUse `yaml:"expect"`
}

OperationRef is a node of execution graph as desfined in the script file. It references a spec operation and contains the needed data.

type Script

type Script struct {
	api.OperationCache
	contract.EntityTrait
	SpecPath   string                   `yaml:"spec"`
	Operations map[string]*OperationRef `yaml:"operations"`
}

Script is a complex API testing scenario. It defines dependencies between various operations and order of their execution.

func (*Script) GetExecutionGraph

func (script *Script) GetExecutionGraph() gcontract.Graph

GetExecutionGraph builds and returns an operation execution graph.

func (*Script) GetNode

func (script *Script) GetNode(graph gcontract.Graph, opRefID string, op contract.Operation, opRef *OperationRef) *ExecutionNode

GetNode returns an ExecutionNode instance corresponding to the opRefID. If such a node exists in the graph, it will be returned, otherwise a new node is created.

func (*Script) SetupAfterDependency

func (script *Script) SetupAfterDependency(graph *ExecutionGraph, opRef *OperationRef, opNode *ExecutionNode) error

SetupAfterDependency adds an edge to the execution graph if opRef has an 'after' specified.

func (*Script) SetupDependencies

func (script *Script) SetupDependencies(
	graph *ExecutionGraph,
	srcParams *OperationDataMap,
	dstParams contract.Set,
	opNode *ExecutionNode,
	opRefID string,
) error

SetupDependencies iterates over the provided map, looks for reference values, collects a list of references operations along with ParameterAccess functions.

Jump to

Keyboard shortcuts

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