Version: v0.0.0-...-5fdf9d8 Latest Latest

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

Go to latest
Published: Nov 9, 2021 License: GPL-3.0 Imports: 22 Imported by: 0




This section is empty.


View Source
var (
	ErrNoSuchNode               = errors.New("no such node")
	ErrNoSuchTestSuite          = errors.New("no such test suite")
	ErrNoSuchTestCase           = errors.New("no such test case")
	ErrMissingClientType        = errors.New("missing client type")
	ErrNoAvailableClients       = errors.New("no available clients")
	ErrTestSuiteRunning         = errors.New("test suite still has running tests")
	ErrMissingOutputDestination = errors.New("test suite requires an output")
	ErrNoSummaryResult          = errors.New("test case must be ended with a summary result")
	ErrDBUpdateFailed           = errors.New("could not update results set")
	ErrTestSuiteLimited         = errors.New("testsuite test count is limited")
View Source
var ErrNetworkNotFound = fmt.Errorf("network not found")

This error is returned by NetworkNameToID if a docker network is not present.


func SplitClientName

func SplitClientName(name string) (string, string)

SplitClientName returns the name and branch components of 'name'.


type Builder

type Builder interface {
	ReadClientMetadata(name string) (*ClientMetadata, error)
	BuildClientImage(ctx context.Context, name string) (string, error)
	BuildSimulatorImage(ctx context.Context, name string) (string, error)

	// ReadFile returns the content of a file in the given image.
	ReadFile(image, path string) ([]byte, error)

Builder can build docker images of clients and simulators.

type ClientDefinition

type ClientDefinition struct {
	Name    string         `json:"name"`
	Version string         `json:"version"`
	Image   string         `json:"-"` // not exposed via API
	Meta    ClientMetadata `json:"meta"`

ClientDefinition is served by the /clients API endpoint to list the available clients

type ClientInfo

type ClientInfo struct {
	ID             string    `json:"id"`
	IP             string    `json:"ip"`
	Name           string    `json:"name"`
	InstantiatedAt time.Time `json:"instantiatedAt"`
	LogFile        string    `json:"logFile"` //Absolute path to the logfile.
	// contains filtered or unexported fields

ClientInfo describes a client that participated in a test case.

type ClientMetadata

type ClientMetadata struct {
	Roles []string `yaml:"roles" json:"roles"`

ClientMetadata is metadata to describe the client in more detail, configured with a YAML file in the client dir.

type ContainerBackend

type ContainerBackend interface {
	// These methods work with containers.
	CreateContainer(ctx context.Context, image string, opt ContainerOptions) (string, error)
	StartContainer(ctx context.Context, containerID string, opt ContainerOptions) (*ContainerInfo, error)
	DeleteContainer(containerID string) error

	// RunEnodeSh runs the / script in the given container and returns its output.
	RunEnodeSh(ctx context.Context, containerID string) (string, error)

	// RunProgram runs a command in the given container and returns its outputs and exit code.
	RunProgram(ctx context.Context, containerID string, cmdline []string) (*ExecInfo, error)

	// These methods configure docker networks.
	NetworkNameToID(name string) (string, error)
	CreateNetwork(name string) (string, error)
	RemoveNetwork(id string) error
	ContainerIP(containerID, networkID string) (net.IP, error)
	ConnectContainer(containerID, networkID string) error
	DisconnectContainer(containerID, networkID string) error

ContainerBackend captures the docker interactions of the simulation API.

type ContainerInfo

type ContainerInfo struct {
	ID      string // docker container ID
	IP      string // IP address
	MAC     string // MAC address. TODO: remove
	LogFile string

	// The wait function returns when the container is stopped.
	// This must be called for all containers that were started
	// to avoid resource leaks.
	Wait func()

ContainerInfo is returned by StartContainer.

type ContainerOptions

type ContainerOptions struct {
	// These options apply when creating the container.
	Env   map[string]string
	Files map[string]*multipart.FileHeader

	// These options apply when starting the container.
	CheckLive uint16 // requests check for the given TCP port
	LogFile   string // if set, container output is written to this file

ContainerOptions contains the launch parameters for docker containers.

type ExecInfo

type ExecInfo struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exitCode"`

ExecInfo is the result of running a script in a client container.

type Inventory

type Inventory struct {
	BaseDir    string
	Clients    map[string]struct{}
	Simulators map[string]struct{}

Inventory keeps names of clients and simulators.

func LoadInventory

func LoadInventory(basedir string) (Inventory, error)

LoadInventory finds all clients and simulators in basedir.

func (*Inventory) AddClient

func (inv *Inventory) AddClient(name string)

AddClient ensures the given client name is known to the inventory. This method exists for unit testing purposes only.

func (*Inventory) AddSimulator

func (inv *Inventory) AddSimulator(name string)

AddSimulator ensures the given simulator name is known to the inventory. This method exists for unit testing purposes only.

func (Inventory) ClientDirectory

func (inv Inventory) ClientDirectory(name string) string

ClientDirectory returns the directory containing the given client's Dockerfile. The client name may contain a branch specifier.

func (Inventory) HasClient

func (inv Inventory) HasClient(name string) bool

HasClient returns true if the inventory contains the given client. The client name may contain a branch specifier.

func (Inventory) HasSimulator

func (inv Inventory) HasSimulator(name string) bool

HasSimulator returns true if the inventory contains the given simulator.

func (*Inventory) MatchSimulators

func (inv *Inventory) MatchSimulators(expr string) ([]string, error)

MatchSimulators returns matching simulator names.

func (Inventory) SimulatorDirectory

func (inv Inventory) SimulatorDirectory(name string) string

SimulatorDirectory returns the directory of containing the given simulator's Dockerfile.

type SimEnv

type SimEnv struct {
	LogDir string

	// Parameters of simulation.
	SimLogLevel    int
	SimParallelism int
	SimTestLimit   int

	// This configures the amount of time the simulation waits
	// for the client to open port 8545 after launching the container.
	ClientStartTimeout time.Duration

	// client name -> client definition
	Definitions map[string]*ClientDefinition

SimEnv contains the simulation parameters.

type TestCase

type TestCase struct {
	Name          string                 `json:"name"`        // Test case short name.
	Description   string                 `json:"description"` // Test case long description in MD.
	Start         time.Time              `json:"start"`
	End           time.Time              `json:"end"`
	SummaryResult TestResult             `json:"summaryResult"` // The result of the whole test case.
	ClientInfo    map[string]*ClientInfo `json:"clientInfo"`    // Info about each client.

TestCase represents a single test case in a test suite.

type TestID

type TestID uint32

TestID identifies a test case context.

func (TestID) String

func (tsID TestID) String() string

type TestManager

type TestManager struct {
	// contains filtered or unexported fields

TestManager collects test results during a simulation run.

func NewTestManager

func NewTestManager(config SimEnv, b ContainerBackend, testLimiter int) *TestManager

func (*TestManager) API

func (manager *TestManager) API() http.Handler

API returns the simulation API handler.

func (*TestManager) ConnectContainer

func (manager *TestManager) ConnectContainer(testSuite TestSuiteID, networkName, containerID string) error

ConnectContainer connects the given container to the given network.

func (*TestManager) ContainerIP

func (manager *TestManager) ContainerIP(testSuite TestSuiteID, networkName, containerID string) (string, error)

ContainerIP gets the IP address of the given container on the given network.

func (*TestManager) CreateNetwork

func (manager *TestManager) CreateNetwork(testSuite TestSuiteID, name string) error

CreateNetwork creates a docker network with the given network name.

func (*TestManager) DisconnectContainer

func (manager *TestManager) DisconnectContainer(testSuite TestSuiteID, networkName, containerID string) error

DisconnectContainer disconnects the given container from the given network.

func (*TestManager) EndTest

func (manager *TestManager) EndTest(testSuiteRun TestSuiteID, testID TestID, summaryResult *TestResult) error

EndTest finishes the test case

func (*TestManager) EndTestSuite

func (manager *TestManager) EndTestSuite(testSuite TestSuiteID) error

EndTestSuite ends the test suite by writing the test suite results to the supplied stream and removing the test suite from the running list

func (*TestManager) GetNodeInfo

func (manager *TestManager) GetNodeInfo(testSuite TestSuiteID, test TestID, nodeID string) (*ClientInfo, error)

GetNodeInfo gets some info on a client belonging to some test

func (*TestManager) IsTestRunning

func (manager *TestManager) IsTestRunning(test TestID) (*TestCase, bool)

IsTestRunning checks if the test is still running and returns it if so.

func (*TestManager) IsTestSuiteRunning

func (manager *TestManager) IsTestSuiteRunning(testSuite TestSuiteID) (*TestSuite, bool)

IsTestSuiteRunning checks if the test suite is still running and returns it if so

func (*TestManager) PruneNetworks

func (manager *TestManager) PruneNetworks(testSuite TestSuiteID) []error

PruneNetworks removes all networks created by the given test suite.

func (*TestManager) RegisterNode

func (manager *TestManager) RegisterNode(testID TestID, nodeID string, nodeInfo *ClientInfo) error

RegisterNode is used by test suite hosts to register the creation of a node in the context of a test

func (*TestManager) RemoveNetwork

func (manager *TestManager) RemoveNetwork(testSuite TestSuiteID, network string) error

RemoveNetwork removes a docker network by the given network name.

func (*TestManager) Results

func (manager *TestManager) Results() map[TestSuiteID]*TestSuite

Results returns the results for all suites that have already ended.

func (*TestManager) SetSimContainerInfo

func (manager *TestManager) SetSimContainerInfo(id, logFile string)

SetSimContainerInfo makes the manager aware of the simulation container. This must be called after creating the simulation container, but before starting it.

func (*TestManager) StartTest

func (manager *TestManager) StartTest(testSuiteID TestSuiteID, name string, description string) (TestID, error)

StartTest starts a new test case, returning the testcase id as a context identifier

func (*TestManager) StartTestSuite

func (manager *TestManager) StartTestSuite(name string, description string) (TestSuiteID, error)

StartTestSuite starts a test suite and returns the context id

func (*TestManager) StopNode

func (manager *TestManager) StopNode(testID TestID, nodeID string) error

StopNode stops a client container.

func (*TestManager) Terminate

func (manager *TestManager) Terminate() error

Terminate forces the termination of any running tests with an error message. This can be called as a cleanup method. If there are no running tests, there is no effect.

type TestResult

type TestResult struct {
	Pass    bool   `json:"pass"`
	Details string `json:"details"`

TestResult is the payload submitted to the EndTest endpoint.

type TestSuite

type TestSuite struct {
	ID             TestSuiteID          `json:"id"`
	Name           string               `json:"name"`
	Description    string               `json:"description"`
	ClientVersions map[string]string    `json:"clientVersions"`
	TestCases      map[TestID]*TestCase `json:"testCases"`
	// the log-file pertaining to the simulator. (may encompass more than just one TestSuite)
	SimulatorLog string `json:"simLog"`

TestSuite is a single run of a simulator, a collection of testcases.

type TestSuiteID

type TestSuiteID uint32

TestSuiteID identifies a test suite context.

func (TestSuiteID) String

func (tsID TestSuiteID) String() string

Jump to

Keyboard shortcuts

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