testcommon

package
v1.39.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

a Logger implementation for tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureOutput

func CaptureOutput(f func()) string

CaptureOutput captures all output written to stdout, stderr and returns it as string credits: https://medium.com/@hau12a1/golang-capturing-log-println-and-fmt-println-output-770209c791b4

func IntegrationAPIURIFromEnv

func IntegrationAPIURIFromEnv() string

IntegrationAPIURIFromEnv return the REST API URL to use for tests

func IntegrationQueueName

func IntegrationQueueName(i int) string

IntegrationQueueName returns the name of the ith test queue

func IntegrationTestConnection

func IntegrationTestConnection(t *testing.T, exchangeName, exchangeType string,
	numQueues int, addRoutingHeader bool) (*amqp.Connection, *amqp.Channel)

IntegrationTestConnection creates connection to rabbitmq broker and sets up optionally an exchange of the given type and bind given number of queues to the exchange. The binding key will aways be the queue name. The queues are named "queue-0" "queue-1" etc (see integrationQueueName() func). If parameter addRoutingHeader is true, then the queue will be bound using an additional routing header ("x-match":"any", "header1":"test0" for first queue etc; this feature is needed by the headers test).

func IntegrationURIFromEnv

func IntegrationURIFromEnv() *url.URL

IntegrationURIFromEnv return the amqp URL to use for tests

func NewRabbitAPIMock

func NewRabbitAPIMock(mode MockMode) *httptest.Server

NewRabbitAPIMock returns a mock server for the rabbitmq http managemet API. It is used by the integration test. Only a very limited subset of resources is support (GET exchanges, bindings, queues, overviews, channels, connections; DELETE connections) Usage:

mockServer := NewRabbitAPIMock(MockModeStd)
defer mockServer.Close()
client f := NewRabbitHTTPClient(mockServe.URL)

func PublishTestMessages

func PublishTestMessages(t *testing.T, ch *amqp.Channel, numMessages int,
	exchangeName, routingKey string, optHeaders amqp.Table)

PublishTestMessages publishes the given number of test messages the exchange exhangeName with the provided routingKey

func VerifyTestMessageOnQueue

func VerifyTestMessageOnQueue(t *testing.T, ch *amqp.Channel, consumer string, numExpected int, queueName string, success chan int)

VerifyTestMessageOnQueue checks that the expected messages were received on the given queue. on success the number of received messages is sent through the provided success channel signalling success.

Types

type MockMode

type MockMode int

MockMode defines operation of the REST API mock

const (
	// MockModeEmpty returns empty structures, except for overview
	MockModeEmpty MockMode = iota
	// MockModeStd simulates broker with active queues and exchanges
	MockModeStd MockMode = iota
)

type TestLogger

type TestLogger struct{}

func NewTestLogger

func NewTestLogger() *TestLogger

func (TestLogger) Debugf

func (s TestLogger) Debugf(format string, a ...interface{})

func (TestLogger) Errorf

func (s TestLogger) Errorf(format string, a ...interface{})

func (TestLogger) Infof

func (s TestLogger) Infof(format string, a ...interface{})

Jump to

Keyboard shortcuts

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