testutil

package
v0.0.0-...-8ae1a0e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PortAllocator = portal.New(
	new(fatalTester),
	portal.WithAddress("127.0.0.1"),
)

PortAllocator is used to acquire unused ports for testing real network listeners.

Functions

func Parallel

func Parallel(t *testing.T)

Parallel runs t in parallel.

The API package has been vetted to be concurrency safe (ish).

func RequireRoot

func RequireRoot(t *testing.T)

func SkipSlow

func SkipSlow(t *testing.T, reason string)

SkipSlow skips a slow test unless NOMAD_SLOW_TEST is set to a true value.

Types

type ACLConfig

type ACLConfig struct {
	Enabled bool `json:"enabled"`
}

ACLConfig is used to configure ACLs

type Advertise struct {
	HTTP string `json:"http,omitempty"`
	RPC  string `json:"rpc,omitempty"`
	Serf string `json:"serf,omitempty"`
}

Advertise is used to configure the addresses to advertise

type ClientConfig

type ClientConfig struct {
	Enabled bool              `json:"enabled"`
	Options map[string]string `json:"options,omitempty"`
}

ClientConfig is used to configure the client

type Consul

type Consul struct {
	Address string `json:"address,omitempty"`
	Auth    string `json:"auth,omitempty"`
	Token   string `json:"token,omitempty"`
}

Consul is used to configure the communication with Consul

type PortsConfig

type PortsConfig struct {
	HTTP int `json:"http,omitempty"`
	RPC  int `json:"rpc,omitempty"`
	Serf int `json:"serf,omitempty"`
}

PortsConfig is used to configure the network ports we use.

type ResponseRecorder

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

ResponseRecorder implements a ResponseWriter which can be written to and read from concurrently. For use in testing streaming APIs where httptest.ResponseRecorder is unsafe for concurrent access. Uses httptest.ResponseRecorder internally and exposes most of the functionality.

func NewResponseRecorder

func NewResponseRecorder() *ResponseRecorder

func (*ResponseRecorder) Flush

func (r *ResponseRecorder) Flush()

Flush sets Flushed=true.

func (*ResponseRecorder) Flushed

func (r *ResponseRecorder) Flushed() bool

Flushed returns true if Flush has been called.

func (*ResponseRecorder) Header

func (r *ResponseRecorder) Header() http.Header

Header returns the response headers. Readers should call HeaderMap() to avoid races due to the server concurrently mutating headers.

func (*ResponseRecorder) HeaderMap

func (r *ResponseRecorder) HeaderMap() http.Header

HeaderMap returns the HTTP headers written before WriteHeader was called.

func (*ResponseRecorder) Read

func (r *ResponseRecorder) Read(p []byte) (int, error)

Read available response bytes. Safe to call concurrently with Write().

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(p []byte) (int, error)

Write to the underlying response buffer. Safe to call concurrent with Read.

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(statusCode int)

WriteHeader sets the response code and freezes the headers returned by HeaderMap. Safe to call concurrent with Read and HeaderMap.

type ServerConfig

type ServerConfig struct {
	Enabled         bool `json:"enabled"`
	BootstrapExpect int  `json:"bootstrap_expect"`
	RaftProtocol    int  `json:"raft_protocol,omitempty"`
}

ServerConfig is used to configure the nomad server.

type ServerConfigCallback

type ServerConfigCallback func(c *TestServerConfig)

ServerConfigCallback is a function interface which can be passed to NewTestServerConfig to modify the server config.

type Telemetry

type Telemetry struct {
	PrometheusMetrics bool `json:"prometheus_metrics"`
}

Telemetry is used to configure the Nomad telemetry setup.

type TestServer

type TestServer struct {
	Config *TestServerConfig

	HTTPAddr   string
	SerfAddr   string
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

TestServer is the main server wrapper struct.

func NewTestServer

func NewTestServer(t testing.T, cb ServerConfigCallback) *TestServer

NewTestServer creates a new TestServer, and makes a call to an optional callback function to modify the configuration.

func (*TestServer) Stop

func (s *TestServer) Stop()

Stop stops the test Nomad server, and removes the Nomad data directory once we are done.

type TestServerConfig

type TestServerConfig struct {
	NodeName          string        `json:"name,omitempty"`
	DataDir           string        `json:"data_dir,omitempty"`
	Region            string        `json:"region,omitempty"`
	DisableCheckpoint bool          `json:"disable_update_check"`
	LogLevel          string        `json:"log_level,omitempty"`
	Consul            *Consul       `json:"consul,omitempty"`
	AdvertiseAddrs    *Advertise    `json:"advertise,omitempty"`
	Ports             *PortsConfig  `json:"ports,omitempty"`
	Server            *ServerConfig `json:"server,omitempty"`
	Client            *ClientConfig `json:"client,omitempty"`
	Vault             *VaultConfig  `json:"vault,omitempty"`
	ACL               *ACLConfig    `json:"acl,omitempty"`
	Telemetry         *Telemetry    `json:"telemetry,omitempty"`
	DevMode           bool          `json:"-"`
	Stdout, Stderr    io.Writer     `json:"-"`
}

TestServerConfig is the main server configuration struct.

type VaultConfig

type VaultConfig struct {
	Enabled bool `json:"enabled"`
}

VaultConfig is used to configure Vault

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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