tdk

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Nomad's Test Development Kit

This package is experimental

The nomad-tdk module provides helpers for writing unit tests for Nomad.

nomad-tdk

Provides Go code for running consul and vault within a test case.

freeport

Provides a way to acquire open ports for use in a test case.

retry

Provides convenience conditional retry logic in a test case.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find added in v0.0.1

func Find(t *testing.T, executable string) string

Find will attempt to locate executable by searching in a few common places in a sensible order for the context of a test case.

Find will search for executable in the order of - the current process - in $PATH - in $GOPATH/bin - in $CWD - in $CWD/bin - in $GOBIN

func NewConsul

func NewConsul(t *testing.T, ccc ConsulConfigCallback) (*Consul, Wait, Stop)

func NewConsulContext

func NewConsulContext(ctx context.Context, t *testing.T, ccc ConsulConfigCallback) (*Consul, Wait, Stop)

Types

type APIConsulConfigCallback

type APIConsulConfigCallback func(c *api.Config)

type Consul

type Consul struct {
	Cmd    *exec.Cmd
	Config *ConsulConfig
}

func (*Consul) Client

func (c *Consul) Client(t *testing.T) *api.Client

func (*Consul) ClientWithConfig

func (c *Consul) ClientWithConfig(t *testing.T, ccc APIConsulConfigCallback) *api.Client

func (*Consul) HTTP

func (c *Consul) HTTP() string

type ConsulConfig

type ConsulConfig struct {
	NodeName          string       `json:"node_name"`
	LogLevel          string       `json:"log_level"`
	Ports             *PortsConfig `json:"ports"`
	Bind              string       `json:"bind_addr"`
	DataDir           string       `json:"data_dir"`
	Bootstrap         bool         `json:"bootstrap"`
	Server            bool         `json:"server"`
	Telemetry         *Telemetry   `json:"telemetry"`
	DisableCheckpoint bool         `json:"disable_update_check,omitempty"`
	Performance       *Performance `json:"performance,omitempty"`
}

func DefaultConsulConfig

func DefaultConsulConfig(t *testing.T) *ConsulConfig

func (*ConsulConfig) Write

func (cc *ConsulConfig) Write(t *testing.T) string

Write writes the configuration JSON file of cc in a fresh temp directory to a file called "consul.json". The temp directory is assigned to cc.DataDir and is the return value.

type ConsulConfigCallback

type ConsulConfigCallback func(c *ConsulConfig)

type Performance

type Performance struct {
	RaftMultiplier int `json:"raft_multiplier,omitempty"`
}

type PortsConfig

type PortsConfig struct {
	RPC     int `json:"server,omitempty"` // Consul (-server-port, ports.server) (8300)
	DNS     int `json:"dns,omitempty"`    // Consul
	HTTP    int `json:"http,omitempty"`
	HTTPS   int `json:"https,omitempty"`
	GRPC    int `json:"grpc,omitempty"`
	SerfLAN int `json:"serf_lan,omitempty"`
	SerfWAN int `json:"serf_wan,omitempty"`
}

func FreeConsulPorts

func FreeConsulPorts(t *testing.T) *PortsConfig

func (*PortsConfig) Cleanup

func (pc *PortsConfig) Cleanup()

type Stop

type Stop func()

type Telemetry

type Telemetry struct {
	DisableCompatibility bool `json:"disable_compat_1.9,omitempty"`
}

type Wait

type Wait func()

Directories

Path Synopsis
Package freeport provides a helper for reserving free TCP ports across multiple processes on the same machine.
Package freeport provides a helper for reserving free TCP ports across multiple processes on the same machine.
Package retry provides support for repeating operations in tests.
Package retry provides support for repeating operations in tests.

Jump to

Keyboard shortcuts

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