Documentation ¶
Index ¶
- func AssertUntil(until time.Duration, test testFn, error errorFn)
- func FilesExist(files []string) (bool, error)
- func IsAppVeyor() bool
- func IsCI() bool
- func IsTravis() bool
- func IsValidCertificate(t *testing.T, caPath string) *x509.Certificate
- func IsValidSigner(t *testing.T, keyPath string) bool
- func RegisterJob(t testing.TB, rpc rpcFn, job *structs.Job)
- func RegisterJobWithToken(t testing.TB, rpc rpcFn, job *structs.Job, token string)
- func TestMultiplier() int64
- func Timeout(original time.Duration) time.Duration
- func VaultVersion() (string, error)
- func Wait(t *testing.T, test testFn)
- func WaitForClient(t testing.TB, rpc rpcFn, nodeID string, region string)
- func WaitForClientStatus(t testing.TB, rpc rpcFn, nodeID string, region string, status string)
- func WaitForFiles(t testing.TB, files []string)
- func WaitForFilesUntil(t testing.TB, files []string, until time.Duration)
- func WaitForJobAllocStatus(t testing.TB, rpc rpcFn, job *structs.Job, allocStatus map[string]int)
- func WaitForJobAllocStatusWithToken(t testing.TB, rpc rpcFn, job *structs.Job, allocStatus map[string]int, ...)
- func WaitForLeader(t testing.TB, rpc rpcFn)
- func WaitForLeaders(t testing.TB, serverRPCs ...rpcFn)
- func WaitForResult(test testFn, error errorFn)
- func WaitForResultRetries(retries int64, test testFn, error errorFn)
- func WaitForResultUntil(until time.Duration, test testFn, errorFunc errorFn)
- func WaitForRunning(t testing.TB, rpc rpcFn, job *structs.Job) []*structs.AllocListStub
- func WaitForRunningWithToken(t testing.TB, rpc rpcFn, job *structs.Job, token string) []*structs.AllocListStub
- func WaitForVotingMembers(t testing.TB, rpc rpcFn, nPeers int)
- type ACLConfig
- type Advertise
- type ClientConfig
- type Consul
- type PortsConfig
- type ResponseRecorder
- func (r *ResponseRecorder) Flush()
- func (r *ResponseRecorder) Flushed() bool
- func (r *ResponseRecorder) Header() http.Header
- func (r *ResponseRecorder) HeaderMap() http.Header
- func (r *ResponseRecorder) Read(p []byte) (int, error)
- func (r *ResponseRecorder) Write(p []byte) (int, error)
- func (r *ResponseRecorder) WriteHeader(statusCode int)
- type ServerConfig
- type ServerConfigCallback
- type TestServer
- type TestServerConfig
- type TestVault
- type VaultConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertUntil ¶ added in v0.6.0
AssertUntil asserts the test function passes throughout the given duration. Otherwise error is called on failure.
func FilesExist ¶ added in v1.1.2
FilesExist verifies all files in the slice are present
func IsAppVeyor ¶ added in v0.9.0
func IsAppVeyor() bool
func IsValidCertificate ¶ added in v1.4.5
func IsValidCertificate(t *testing.T, caPath string) *x509.Certificate
Assert CA file exists and is a valid CA Returns the CA
func IsValidSigner ¶ added in v1.4.5
Assert key file exists and is a valid signer returns a bool
func RegisterJobWithToken ¶ added in v0.9.2
RegisterJobWithToken registers a job and uses the job's Region and Namespace.
func TestMultiplier ¶ added in v0.3.0
func TestMultiplier() int64
TestMultiplier returns a multiplier for retries and waits given environment the tests are being run under.
func Timeout ¶ added in v0.8.0
Timeout takes the desired timeout and increases it if running in Travis
func VaultVersion ¶ added in v0.5.3
VaultVersion returns the Vault version as a string or an error if it couldn't be determined
func WaitForClient ¶ added in v1.0.0
WaitForClient blocks until the client can be found
func WaitForClientStatus ¶ added in v1.3.10
WaitForClientStatus blocks until the client is in the expected status.
func WaitForFiles ¶ added in v1.0.0
WaitForFiles blocks until all the files in the slice are present
func WaitForFilesUntil ¶ added in v1.1.2
WaitForFilesUntil blocks until duration or all the files in the slice are present
func WaitForJobAllocStatus ¶ added in v1.3.10
WaitforJobAllocStatus blocks until the ClientStatus of allocations for a job match the expected map of <ClientStatus>: <count>.
func WaitForJobAllocStatusWithToken ¶ added in v1.3.10
func WaitForJobAllocStatusWithToken(t testing.TB, rpc rpcFn, job *structs.Job, allocStatus map[string]int, token string)
WaitForJobAllocStatusWithToken behaves the same way as WaitForJobAllocStatus but is used for clusters with ACL enabled.
func WaitForLeader ¶
WaitForLeader blocks until a leader is elected.
func WaitForLeaders ¶ added in v1.3.12
WaitForLeaders blocks until each serverRPC knows the leader.
func WaitForResult ¶
func WaitForResult(test testFn, error errorFn)
func WaitForResultRetries ¶ added in v0.3.0
func WaitForResultRetries(retries int64, test testFn, error errorFn)
func WaitForResultUntil ¶ added in v1.1.2
WaitForResultUntil waits the duration for the test to pass. Otherwise error is called after the deadline expires.
func WaitForRunning ¶ added in v0.8.5
WaitForRunning runs a job and blocks until all allocs are out of pending.
func WaitForRunningWithToken ¶ added in v0.9.2
func WaitForVotingMembers ¶ added in v0.10.0
WaitForVotingMembers blocks until autopilot promotes all server peers to be voting members.
Useful for tests that change cluster topology (e.g. kill a node) that should wait until cluster is stable.
Types ¶
type ACLConfig ¶ added in v0.7.0
type ACLConfig struct {
Enabled bool `json:"enabled"`
}
ACLConfig is used to configure ACLs
type Advertise ¶ added in v0.5.0
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"`
}
ClientConfig is used to configure the client
type Consul ¶ added in v0.8.0
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 ¶ added in v0.9.0
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 ¶ added in v0.9.0
func NewResponseRecorder() *ResponseRecorder
func (*ResponseRecorder) Flush ¶ added in v0.9.0
func (r *ResponseRecorder) Flush()
Flush sets Flushed=true.
func (*ResponseRecorder) Flushed ¶ added in v0.9.0
func (r *ResponseRecorder) Flushed() bool
Flushed returns true if Flush has been called.
func (*ResponseRecorder) Header ¶ added in v0.9.0
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 ¶ added in v0.9.0
func (r *ResponseRecorder) HeaderMap() http.Header
HeaderMap returns the HTTP headers written before WriteHeader was called.
func (*ResponseRecorder) Read ¶ added in v0.9.0
func (r *ResponseRecorder) Read(p []byte) (int, error)
Read available response bytes. Safe to call concurrently with Write().
func (*ResponseRecorder) Write ¶ added in v0.9.0
func (r *ResponseRecorder) Write(p []byte) (int, error)
Write to the underlying response buffer. Safe to call concurrent with Read.
func (*ResponseRecorder) WriteHeader ¶ added in v0.9.0
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 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"` DevMode bool `json:"-"` Stdout, Stderr io.Writer `json:"-"` }
TestServerConfig is the main server configuration struct.
type TestVault ¶ added in v0.5.0
type TestVault struct { Addr string HTTPAddr string RootToken string Config *config.VaultConfig Client *vapi.Client // contains filtered or unexported fields }
TestVault wraps a test Vault server launched in dev mode, suitable for testing.
func NewTestVault ¶ added in v0.5.0
NewTestVault returns a new TestVault instance that is ready for API calls
func NewTestVaultDelayed ¶ added in v0.6.0
NewTestVaultDelayed returns a test Vault server that has not been started. Start must be called and it is the callers responsibility to deal with any port conflicts that may occur and retry accordingly.