test

package module
v0.0.0-...-558ec45 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

README

test

External service launcher for running unit test

Docker images

Pull the following image before start

docker pull elasticsearch:2.4 redis:3-alpine quay.io/coreos/etcd nats

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(filePath string, tplStr string, vars map[string]interface{}) error

ApplyTemplate applies given variables to the "tplStr" and stores to "filePath"

func BookPorts

func BookPorts(num int, host ...string) ([]int, error)

BookPorts books free portsx

func CheckExecutable

func CheckExecutable(names ...string) error

CheckExecutable checks if given names are executables

func CheckListening

func CheckListening(ports ...int) bool

CheckListening checks if localhost is listening given ports

func CombineError

func CombineError(errs ...error) error

CombineError given errors into one err, note that nil error will be ignored

func Exec

func Exec(workdir string, envs []string, stdin io.Reader, name string, arg ...interface{}) error

Exec runs "name" and "arg" in directory "workdir" with environements "envs" and wait util process finined. It returns error if fail to execute or exit code is not zero.

func GetPort

func GetPort() int

func NewDockerClient

func NewDockerClient() (cl *docker.Client)

NewDockerClient create docker client via unix socket

func RegisterService

func RegisterService(t ServiceType, f ServiceFactory)

RegisterService registers a service factory of the given type

func RemoveContainer

func RemoveContainer(client *docker.Client, container *docker.Container) error

RemoveContainer remove the started container

func StartContainer

func StartContainer(client *docker.Client, options ...ContainerOptionFunc) (c *docker.Container, ipaddr string, err error)

StartContainer starts the required container

func WaitPortAvail

func WaitPortAvail(port int, timeout time.Duration, host ...string) error

WaitPortAvail waits until the port becomes dialable. It returns error if it's not available after timeout.

Types

type ContainerNode

type ContainerNode struct {
	Command []string
	Env     []string
	Image   string
	Port    []string
}

type ContainerOptionFunc

type ContainerOptionFunc func(*docker.CreateContainerOptions) error

ContainerOptionFunc is a function that configures a Client. It is used in createDockerOptions.

func SetCommand

func SetCommand(cmd []string) ContainerOptionFunc

SetCommand set the command for the container

func SetEnv

func SetEnv(env []string) ContainerOptionFunc

SetEnv set the command for the container

func SetExposedPorts

func SetExposedPorts(ports []string) ContainerOptionFunc

TODO:

PortBindings: map[docker.Port][]docker.PortBinding{
	"8888/tcp": {{HostIP: "", HostPort: "12345"}},
},

SetExposedPorts accepts format as "1234/tcp", "5678/udp"

func SetImage

func SetImage(image string) ContainerOptionFunc

SetImage set the docker image for the container

type HbaseService

type HbaseService interface {
	// RunScript runs the hbase script directly
	RunScript(script string) error
	// RunScript runs the hbase script file
	RunScriptFromFile(file string) error
}

HbaseService represents hbase service

type Service

type Service interface {
	// Start launches the service and return its listening port
	Start() (string, error)
	// Stop stops the service
	Stop() error
	// StartDocker launches the service and return its listening port via docker
	StartDocker(*docker.Client) (string, error)
	// Stop stops the service via docker
	StopDocker(*docker.Client) error
}

Service represents a service

type ServiceDocker

type ServiceDocker interface {
	// Start creates and starts an instance of supported service by the give type. It
	// returns its listening ip:port and the corresponding stop function.
	Start(ServiceType, ...ServiceOption) (ipport string, stopFunc func() error, err error)
	// StopAll stop all created services
	StopAll() error
	// Get retruns service, return nil if no service for the given ipport
	Get(ipport string) interface{}
}

ServiceDocker defines an interface to create service via docker

func NewServiceDocker

func NewServiceDocker() ServiceDocker

NewServiceDocker returns an instance of ServiceDocker TODO: with specified docker address

type ServiceFactory

type ServiceFactory func() Service

ServiceFactory represents service factory

type ServiceLauncher

type ServiceLauncher interface {
	// Start creates and starts an instance of supported service by the give type. It
	// returns its listening ip:port and the corresponding stop function.
	Start(ServiceType, ...ServiceOption) (ipport string, stopFunc func() error, err error)
	// StopAll stop all created services
	StopAll() error
	// Get retruns service, return nil if no service for the given ipport
	Get(ipport string) interface{}
}

ServiceLauncher defines an interface to create service

func NewServiceLauncher

func NewServiceLauncher() ServiceLauncher

NewServiceLauncher returns an instance of ServiceLauncher

type ServiceOption

type ServiceOption func(Service) error

ServiceOption defines option function to setup service

func RedisAuth

func RedisAuth(password string) ServiceOption

func RedisMemory

func RedisMemory(maxMem string) ServiceOption

func RedisPort

func RedisPort(port int) ServiceOption

type ServiceType

type ServiceType string

ServiceType defines type

const (
	ZooKeeper     ServiceType = "zookeeper"
	HBase         ServiceType = "hbase"
	Redis         ServiceType = "redis"
	Etcd          ServiceType = "etcd"
	Gnatsd        ServiceType = "gnatsd"
	Disque        ServiceType = "disque"
	Consul        ServiceType = "consul"
	ElasticSearch ServiceType = "elasticsearch"
)

supported service types

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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