Documentation ¶
Index ¶
- Constants
- func BuildArgs(flags map[string]string) []string
- func EmptyFlags() map[string]string
- func Equals(value float64) func(sums ...float64) bool
- func EqualsAmongTwo(sums ...float64) bool
- func EqualsSingle(expected float64) func(float64) bool
- func Greater(value float64) func(sums ...float64) bool
- func GreaterAmongTwo(sums ...float64) bool
- func GreaterOrEqual(value float64) func(sums ...float64) bool
- func Less(value float64) func(sums ...float64) bool
- func LessAmongTwo(sums ...float64) bool
- func MergeFlags(inputs ...map[string]string) map[string]string
- func MergeFlagsWithoutRemovingEmpty(inputs ...map[string]string) map[string]string
- func NetworkContainerHost(networkName, containerName string) string
- func NetworkContainerHostPort(networkName, containerName string, port int) string
- func NewLogger(w io.Writer) *logger
- func RunCommandAndGetOutput(name string, args ...string) ([]byte, error)
- func RunCommandWithTimeoutAndGetOutput(timeout time.Duration, name string, args ...string) ([]byte, error)
- func SumValues(values []float64) float64
- type CmdReadinessProbe
- type Command
- type CompositeHTTPService
- func (s *CompositeHTTPService) Instances() []*HTTPService
- func (s *CompositeHTTPService) NumInstances() int
- func (s *CompositeHTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error)
- func (s *CompositeHTTPService) WaitSumMetrics(isExpected func(sums ...float64) bool, metricNames ...string) error
- func (s *CompositeHTTPService) WaitSumMetricsWithOptions(isExpected func(sums ...float64) bool, metricNames []string, ...) error
- type ConcreteService
- func (s *ConcreteService) Endpoint(port int) string
- func (s *ConcreteService) Exec(command *Command) (string, string, error)
- func (s *ConcreteService) Kill() error
- func (s *ConcreteService) Name() string
- func (s *ConcreteService) NetworkEndpoint(port int) string
- func (s *ConcreteService) NetworkEndpointFor(networkName string, port int) string
- func (s *ConcreteService) Ready() error
- func (s *ConcreteService) SetBackoff(cfg backoff.Config)
- func (s *ConcreteService) SetEnvVars(env map[string]string)
- func (s *ConcreteService) SetReadinessProbe(probe ReadinessProbe)
- func (s *ConcreteService) SetUser(user string)
- func (s *ConcreteService) Start(logger log.Logger, networkName, sharedDir string) (err error)
- func (s *ConcreteService) Stop() error
- func (s *ConcreteService) WaitForRunning() (err error)
- func (s *ConcreteService) WaitReady() (err error)
- type HTTPReadinessProbe
- type HTTPService
- func (s *HTTPService) HTTPEndpoint() string
- func (s *HTTPService) HTTPPort() int
- func (s *HTTPService) Metrics() (_ string, err error)
- func (s *HTTPService) NetworkHTTPEndpoint() string
- func (s *HTTPService) NetworkHTTPEndpointFor(networkName string) string
- func (s *HTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error)
- func (s *HTTPService) WaitRemovedMetric(metricName string, opts ...MetricsOption) error
- func (s *HTTPService) WaitSumMetrics(isExpected func(sums ...float64) bool, metricNames ...string) error
- func (s *HTTPService) WaitSumMetricsWithOptions(isExpected func(sums ...float64) bool, metricNames []string, ...) error
- type LinePrefixLogger
- type MetricsOption
- type ReadinessProbe
- type Scenario
- func (s *Scenario) Close()
- func (s *Scenario) NetworkName() string
- func (s *Scenario) SharedDir() string
- func (s *Scenario) Start(services ...Service) error
- func (s *Scenario) StartAndWaitReady(services ...Service) error
- func (s *Scenario) Stop(services ...Service) error
- func (s *Scenario) WaitReady(services ...Service) error
- type ScenarioOption
- type Service
- type TCPReadinessProbe
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func EmptyFlags ¶
func Equals ¶
Equals is an isExpected function for WaitSumMetrics that returns true if given single sum is equals to given value.
func EqualsAmongTwo ¶
EqualsAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is equal to the second. NOTE: Be careful on scrapes in between of process that changes two metrics. Those are usually not atomic.
func EqualsSingle ¶
func Greater ¶
Greater is an isExpected function for WaitSumMetrics that returns true if given single sum is greater than given value.
func GreaterAmongTwo ¶
GreaterAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is greater than second. NOTE: Be careful on scrapes in between of process that changes two metrics. Those are usually not atomic.
func GreaterOrEqual ¶
GreaterOrEqual is an isExpected function for WaitSumMetrics that returns true if given single sum is greater or equal than given value.
func Less ¶
Less is an isExpected function for WaitSumMetrics that returns true if given single sum is less than given value.
func LessAmongTwo ¶
LessAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is smaller than second. NOTE: Be careful on scrapes in between of process that changes two metrics. Those are usually not atomic.
func NetworkContainerHost ¶
NetworkContainerHost return the hostname of the container within the network. This is the address a container should use to connect to other containers.
func NetworkContainerHostPort ¶
NetworkContainerHostPort return the host:port address of a container within the network.
func RunCommandAndGetOutput ¶
Types ¶
type CmdReadinessProbe ¶
type CmdReadinessProbe struct {
// contains filtered or unexported fields
}
CmdReadinessProbe checks readiness by `Exec`ing a command (within container) which returns 0 to consider status being ready.
func NewCmdReadinessProbe ¶
func NewCmdReadinessProbe(cmd *Command) *CmdReadinessProbe
func (*CmdReadinessProbe) Ready ¶
func (p *CmdReadinessProbe) Ready(service *ConcreteService) error
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func NewCommand ¶
type CompositeHTTPService ¶
type CompositeHTTPService struct {
// contains filtered or unexported fields
}
CompositeHTTPService abstract an higher-level service composed by more than one HTTPService.
func NewCompositeHTTPService ¶
func NewCompositeHTTPService(services ...*HTTPService) *CompositeHTTPService
func (*CompositeHTTPService) Instances ¶
func (s *CompositeHTTPService) Instances() []*HTTPService
func (*CompositeHTTPService) NumInstances ¶
func (s *CompositeHTTPService) NumInstances() int
func (*CompositeHTTPService) SumMetrics ¶
func (s *CompositeHTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error)
SumMetrics returns the sum of the values of each given metric names.
func (*CompositeHTTPService) WaitSumMetrics ¶
func (s *CompositeHTTPService) WaitSumMetrics(isExpected func(sums ...float64) bool, metricNames ...string) error
WaitSumMetrics waits for at least one instance of each given metric names to be present and their sums, returning true when passed to given isExpected(...).
func (*CompositeHTTPService) WaitSumMetricsWithOptions ¶
func (s *CompositeHTTPService) WaitSumMetricsWithOptions(isExpected func(sums ...float64) bool, metricNames []string, opts ...MetricsOption) error
type ConcreteService ¶
type ConcreteService struct {
// contains filtered or unexported fields
}
ConcreteService represents microservice with optional ports which will be discoverable from docker with <name>:<port>. For connecting from test, use `Endpoint` method.
ConcreteService can be reused (started and stopped many time), but it can represent only one running container at the time.
func NewConcreteService ¶
func NewConcreteService( name string, image string, command *Command, readiness ReadinessProbe, networkPorts ...int, ) *ConcreteService
func (*ConcreteService) Endpoint ¶
func (s *ConcreteService) Endpoint(port int) string
Endpoint returns external (from host perspective) service endpoint (host:port) for given internal port. External means that it will be accessible only from host, but not from docker containers.
If your service is not running, this method returns incorrect `stopped` endpoint.
func (*ConcreteService) Exec ¶
func (s *ConcreteService) Exec(command *Command) (string, string, error)
Exec runs the provided against a the docker container specified by this service. It returns the stdout, stderr, and error response from attempting to run the command.
func (*ConcreteService) Kill ¶
func (s *ConcreteService) Kill() error
func (*ConcreteService) Name ¶
func (s *ConcreteService) Name() string
func (*ConcreteService) NetworkEndpoint ¶
func (s *ConcreteService) NetworkEndpoint(port int) string
NetworkEndpoint returns internal service endpoint (host:port) for given internal port. Internal means that it will be accessible only from docker containers within the network that this service is running in. If you configure your local resolver with docker DNS namespace you can access it from host as well. Use `Endpoint` for host access.
If your service is not running, use `NetworkEndpointFor` instead.
func (*ConcreteService) NetworkEndpointFor ¶
func (s *ConcreteService) NetworkEndpointFor(networkName string, port int) string
NetworkEndpointFor returns internal service endpoint (host:port) for given internal port and network. Internal means that it will be accessible only from docker containers within the given network. If you configure your local resolver with docker DNS namespace you can access it from host as well.
This method return correct endpoint for the service in any state.
func (*ConcreteService) Ready ¶
func (s *ConcreteService) Ready() error
func (*ConcreteService) SetBackoff ¶
func (s *ConcreteService) SetBackoff(cfg backoff.Config)
func (*ConcreteService) SetEnvVars ¶
func (s *ConcreteService) SetEnvVars(env map[string]string)
func (*ConcreteService) SetReadinessProbe ¶
func (s *ConcreteService) SetReadinessProbe(probe ReadinessProbe)
func (*ConcreteService) SetUser ¶
func (s *ConcreteService) SetUser(user string)
func (*ConcreteService) Start ¶
func (s *ConcreteService) Start(logger log.Logger, networkName, sharedDir string) (err error)
func (*ConcreteService) Stop ¶
func (s *ConcreteService) Stop() error
func (*ConcreteService) WaitForRunning ¶
func (s *ConcreteService) WaitForRunning() (err error)
func (*ConcreteService) WaitReady ¶
func (s *ConcreteService) WaitReady() (err error)
type HTTPReadinessProbe ¶
type HTTPReadinessProbe struct {
// contains filtered or unexported fields
}
HTTPReadinessProbe checks readiness by making HTTP call and checking for expected HTTP status code.
func NewHTTPReadinessProbe ¶
func NewHTTPReadinessProbe(port int, path string, expectedStatusRangeStart, expectedStatusRangeEnd int, expectedContent ...string) *HTTPReadinessProbe
func (*HTTPReadinessProbe) Ready ¶
func (p *HTTPReadinessProbe) Ready(service *ConcreteService) (err error)
type HTTPService ¶
type HTTPService struct { *ConcreteService // contains filtered or unexported fields }
HTTPService represents opinionated microservice with at least HTTP port that as mandatory requirement, serves metrics.
func NewHTTPService ¶
func NewHTTPService( name string, image string, command *Command, readiness ReadinessProbe, httpPort int, otherPorts ...int, ) *HTTPService
func (*HTTPService) HTTPEndpoint ¶
func (s *HTTPService) HTTPEndpoint() string
func (*HTTPService) HTTPPort ¶
func (s *HTTPService) HTTPPort() int
func (*HTTPService) Metrics ¶
func (s *HTTPService) Metrics() (_ string, err error)
func (*HTTPService) NetworkHTTPEndpoint ¶
func (s *HTTPService) NetworkHTTPEndpoint() string
func (*HTTPService) NetworkHTTPEndpointFor ¶
func (s *HTTPService) NetworkHTTPEndpointFor(networkName string) string
func (*HTTPService) SumMetrics ¶
func (s *HTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error)
SumMetrics returns the sum of the values of each given metric names.
func (*HTTPService) WaitRemovedMetric ¶
func (s *HTTPService) WaitRemovedMetric(metricName string, opts ...MetricsOption) error
WaitRemovedMetric waits until a metric disappear from the list of metrics exported by the service.
func (*HTTPService) WaitSumMetrics ¶
func (s *HTTPService) WaitSumMetrics(isExpected func(sums ...float64) bool, metricNames ...string) error
WaitSumMetrics waits for at least one instance of each given metric names to be present and their sums, returning true when passed to given isExpected(...).
func (*HTTPService) WaitSumMetricsWithOptions ¶
func (s *HTTPService) WaitSumMetricsWithOptions(isExpected func(sums ...float64) bool, metricNames []string, opts ...MetricsOption) error
type LinePrefixLogger ¶
type LinePrefixLogger struct {
// contains filtered or unexported fields
}
type MetricsOption ¶
type MetricsOption func(*metricsOptions)
MetricsOption defined the signature of a function used to manipulate options.
func SkipMissingMetrics ¶
func SkipMissingMetrics() MetricsOption
SkipWaitMissingMetrics is an option to skip/ignore whenever an expected metric is missing.
func WaitMissingMetrics ¶
func WaitMissingMetrics() MetricsOption
WithWaitMissingMetrics is an option to wait whenever an expected metric is missing. If this option is not enabled, will return error on missing metrics.
func WithLabelMatchers ¶
func WithLabelMatchers(matchers ...*matchers.Matcher) MetricsOption
WithLabelMatchers is an option to filter only matching series.
func WithMetricCount ¶
func WithMetricCount() MetricsOption
WithMetricCount is an option to get the histogram/summary count as metric value.
type ReadinessProbe ¶
type ReadinessProbe interface {
Ready(service *ConcreteService) (err error)
}
type Scenario ¶
type Scenario struct {
// contains filtered or unexported fields
}
Scenario allows to manage deployments for single testing scenario.
func NewScenario ¶
func NewScenario(opts ...ScenarioOption) (_ *Scenario, err error)
NewScenario creates new Scenario.
func (*Scenario) NetworkName ¶
NetworkName returns the network name that scenario is responsible for.
func (*Scenario) SharedDir ¶
SharedDir returns the absolute path of the directory on the host that is shared with all services in docker.
func (*Scenario) StartAndWaitReady ¶
type ScenarioOption ¶
type ScenarioOption func(*scenarioOptions)
ScenarioOption defined the signature of a function used to manipulate options.
func WithLogger ¶
func WithLogger(logger log.Logger) ScenarioOption
WithLogger tells scenario to use custom logger default one (stdout).
func WithNetworkName ¶
func WithNetworkName(networkName string) ScenarioOption
WithNetworkName tells scenario to use custom network name instead of UUID.
type Service ¶
type Service interface { Name() string Start(logger log.Logger, networkName, dir string) error WaitReady() error // It should be ok to Stop and Kill more than once, with next invokes being noop. Kill() error Stop() error }
Service is unified service interface that Scenario can manage.
type TCPReadinessProbe ¶
type TCPReadinessProbe struct {
// contains filtered or unexported fields
}
TCPReadinessProbe checks readiness by ensure a TCP connection can be established.
func NewTCPReadinessProbe ¶
func NewTCPReadinessProbe(port int) *TCPReadinessProbe
func (*TCPReadinessProbe) Ready ¶
func (p *TCPReadinessProbe) Ready(service *ConcreteService) (err error)