common

package
v0.0.0-...-5c345c6 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2016 License: MIT Imports: 19 Imported by: 0

README

common

common

Package common contains common utilities and suites to be used in other tests

Usage

func Build
func Build() error

Build builds the current go package.

func ConsulMaker
func ConsulMaker(port uint16, dir, prefix string) *exec.Cmd

ConsulMaker will create an exec.Cmd to run consul with the given paramaters

func EtcdMaker
func EtcdMaker(port uint16, dir, prefix string) *exec.Cmd

EtcdMaker will create an exec.Cmd to run etcd with the given paramaters

func ExitStatus
func ExitStatus(err error) int

ExitStatus tries to extract an exit status code from an error.

type Cmd
type Cmd struct {
	Cmd *exec.Cmd
	Out *bytes.Buffer
}

Cmd wraps an exec.Cmd with monitoring and easy access to output.

func ExecSync
func ExecSync(cmdName string, args ...string) (*Cmd, error)

ExecSync runs a command synchronously, waiting for it to complete.

func Start
func Start(cmdName string, args ...string) (*Cmd, error)

Start runs a command asynchronously.

func (*Cmd) Alive
func (c *Cmd) Alive() bool

Alive returns whether the command process is alive or not.

func (*Cmd) ExitStatus
func (c *Cmd) ExitStatus() (int, error)

ExitStatus returns the exit status code and error for a command. If the command is still running or in the process of being shut down, the exit code will be 0 and the returned error will be non-nil.

func (*Cmd) Stop
func (c *Cmd) Stop() error

Stop kills a running command and waits until it exits. The error returned is from the Kill call, not the error of the exiting command. For the latter, call c.Err() after c.Stop().

func (*Cmd) Wait
func (c *Cmd) Wait() error

Wait waits for a command to finish and returns the exit error.

type Suite
type Suite struct {
	suite.Suite
	KVDir      string
	KVPrefix   string
	KVPort     uint16
	KVURL      string
	KV         kv.KV
	KVCmd      *exec.Cmd
	KVCmdMaker func(uint16, string, string) *exec.Cmd
	TestPrefix string
}

Suite sets up a general test suite with setup/teardown.

func (*Suite) DoRequest
func (s *Suite) DoRequest(method, url string, expectedRespCode int, postBodyStruct interface{}, respBody interface{}) *http.Response

DoRequest is a convenience method for making an http request and doing basic handling of the response.

func (*Suite) Messager
func (s *Suite) Messager(prefix string) func(...interface{}) string

Messager generates a function for creating a string message with a prefix.

func (*Suite) PrefixKey
func (s *Suite) PrefixKey(key string) string

PrefixKey generates a kv key using the set prefix

func (*Suite) SetupSuite
func (s *Suite) SetupSuite()

SetupSuite runs a new kv instance.

func (*Suite) SetupTest
func (s *Suite) SetupTest()

SetupTest prepares anything needed per test.

func (*Suite) TearDownSuite
func (s *Suite) TearDownSuite()

TearDownSuite stops the kv instance and removes all data.

func (*Suite) TearDownTest
func (s *Suite) TearDownTest()

TearDownTest cleans the kv instance.

-- Generated with godocdown

Documentation

Overview

Package common contains common utilities and suites to be used in other tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build() error

Build builds the current go package.

func ConsulMaker

func ConsulMaker(port uint16, dir, prefix string) *exec.Cmd

ConsulMaker will create an exec.Cmd to run consul with the given paramaters

func EtcdMaker

func EtcdMaker(port uint16, dir, prefix string) *exec.Cmd

EtcdMaker will create an exec.Cmd to run etcd with the given paramaters

func ExitStatus

func ExitStatus(err error) int

ExitStatus tries to extract an exit status code from an error.

Types

type Cmd

type Cmd struct {
	Cmd *exec.Cmd
	Out *bytes.Buffer
	// contains filtered or unexported fields
}

Cmd wraps an exec.Cmd with monitoring and easy access to output.

func ExecSync

func ExecSync(cmdName string, args ...string) (*Cmd, error)

ExecSync runs a command synchronously, waiting for it to complete.

func Start

func Start(cmdName string, args ...string) (*Cmd, error)

Start runs a command asynchronously.

func (*Cmd) Alive

func (c *Cmd) Alive() bool

Alive returns whether the command process is alive or not.

func (*Cmd) ExitStatus

func (c *Cmd) ExitStatus() (int, error)

ExitStatus returns the exit status code and error for a command. If the command is still running or in the process of being shut down, the exit code will be 0 and the returned error will be non-nil.

func (*Cmd) Stop

func (c *Cmd) Stop() error

Stop kills a running command and waits until it exits. The error returned is from the Kill call, not the error of the exiting command. For the latter, call c.Err() after c.Stop().

func (*Cmd) Wait

func (c *Cmd) Wait() error

Wait waits for a command to finish and returns the exit error.

type Suite

type Suite struct {
	suite.Suite
	KVDir      string
	KVPrefix   string
	KVPort     uint16
	KVURL      string
	KV         kv.KV
	KVCmd      *exec.Cmd
	KVCmdMaker func(uint16, string, string) *exec.Cmd
	TestPrefix string
}

Suite sets up a general test suite with setup/teardown.

func (*Suite) DoRequest

func (s *Suite) DoRequest(method, url string, expectedRespCode int, postBodyStruct interface{}, respBody interface{}) *http.Response

DoRequest is a convenience method for making an http request and doing basic handling of the response.

func (*Suite) Messager

func (s *Suite) Messager(prefix string) func(...interface{}) string

Messager generates a function for creating a string message with a prefix.

func (*Suite) PrefixKey

func (s *Suite) PrefixKey(key string) string

PrefixKey generates a kv key using the set prefix

func (*Suite) SetupSuite

func (s *Suite) SetupSuite()

SetupSuite runs a new kv instance.

func (*Suite) SetupTest

func (s *Suite) SetupTest()

SetupTest prepares anything needed per test.

func (*Suite) TearDownSuite

func (s *Suite) TearDownSuite()

TearDownSuite stops the kv instance and removes all data.

func (*Suite) TearDownTest

func (s *Suite) TearDownTest()

TearDownTest cleans the kv instance.

Jump to

Keyboard shortcuts

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