timeline

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

Testing Badge Linting Badge

timeline

Library for executing a serialized event sequence

Summary

This is a simple library that can generate a described sequence of events to allow for testing of code response.

The library comes packaged with a few event types and the user can map additional actions and synchronizers for timeline to execute.

Sequence

A timeline sequence is composed of events that are either synchornizers or actions. Synchronizers indicate timeline should synchornize the event flow with something such as an OS signal or a timer expiration. Actions simply call functions in your code base.

Example

  timeline:
    - sync: SignalRecv
      inputs:
        signal: SIGUSR1
    - action: NetworkBlock
      block: true
      inputs:
        dest: 10.0.0.1/32
    - sync: TimerWait
      inputs:
        duration: 30s
    - action: NetworkAllow
      block: false
      inputs:
        dest: 10.0.0.1/32 

The above serialization indicates a timeline that will wait until the executable receives the SIGUSR1 signal and then execute a function the user has mapped to NetworkBlock passing the inputs object as a parameter. It will block until that function returns and then the timeline will wait idly for 30s before calling the function for NetworkAllow.

Packaged Event Types

Technically there is little difference between an action and a synchronizer. The serialization only differentiates them to reason about the intent of the timeline.

Synchronizers

Synchronizers are functions that work to synchronize the timeline with external or environmental conditions.

SignalRecv

Synchronize the timeline execution with OS signals that are sent to the rcon process. This could used to synchronize an external measurement or testing system with described changes made to the runtime context.

TimerWait

This is a basic timer to pause execution of the timeline for a static amount of time described as a Go ParseDuration format.

Actions

Actions are functions that can be used to change the runtime context. This could be to emulate failed network connectivity, change the contents of a file, or just have rcon log a message.

LogMessage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Sync   string
	Action string
	Inputs interface{}
	Block  bool
}

type Timeline

type Timeline struct {
	Events    []Event
	Variables map[string]interface{}
	// contains filtered or unexported fields
}

func NewTimeline

func NewTimeline() *Timeline

func (*Timeline) AddEvent

func (t *Timeline) AddEvent(e Event)

func (*Timeline) Execute

func (t *Timeline) Execute()

func (*Timeline) GetVariable

func (t *Timeline) GetVariable(name string) (interface{}, bool)

func (*Timeline) MapAction

func (t *Timeline) MapAction(action string, actor func(interface{}, map[string]interface{}) error)

func (*Timeline) MapSync

func (t *Timeline) MapSync(sync string, syncer func(interface{}, map[string]interface{}) error)

func (*Timeline) SetVariable

func (t *Timeline) SetVariable(name string, val interface{})

Jump to

Keyboard shortcuts

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