Documentation
¶
Overview ¶
Package amqptest contains testing utilities for amqp types.
Index ¶
- Constants
- func GetTestConnection(tb testing.TB) *amqp.Connection
- type AmqpSuite
- func (amqpSuite *AmqpSuite) ChannelConsume() *amqp.Channel
- func (amqpSuite *AmqpSuite) ChannelConsumeTester() *amqp.ChannelTesting
- func (amqpSuite *AmqpSuite) ChannelPublish() *amqp.Channel
- func (amqpSuite *AmqpSuite) ChannelPublishTester() *amqp.ChannelTesting
- func (amqpSuite *AmqpSuite) ConnConsume() *amqp.Connection
- func (amqpSuite *AmqpSuite) ConnPublish() *amqp.Connection
- func (amqpSuite *AmqpSuite) CreateTestExchange(name string, kind string, cleanup bool)
- func (amqpSuite *AmqpSuite) CreateTestQueue(name string, exchange string, exchangeKey string, cleanup bool) amqp.Queue
- func (amqpSuite *AmqpSuite) GetMessage(queueName string, autoAck bool) amqp.Delivery
- func (amqpSuite *AmqpSuite) PublishMessages(t *testing.T, exchange string, key string, count int)
- func (amqpSuite *AmqpSuite) ReplaceChannels()
- func (amqpSuite *AmqpSuite) SetupSuite()
- func (amqpSuite *AmqpSuite) SetupTest()
- func (amqpSuite *AmqpSuite) TearDownSuite()
- type Assertions
- type ChannelSuiteOpts
- type ChannelTesting
- type ConnectionTesting
- type InnerSuite
Constants ¶
const (
// TestDialAddress is the default address for a test broker.
TestDialAddress = "amqp://localhost:57018"
)
Variables ¶
This section is empty.
Functions ¶
func GetTestConnection ¶
func GetTestConnection(tb testing.TB) *amqp.Connection
GetTestConnection creates a new connection to amqp://localhost:57018, where our test broker will be listening.
t.FailNow() is called on any errors.
Types ¶
type AmqpSuite ¶
type AmqpSuite struct { // InnerSuite is the embedded suite type. InnerSuite // Opts is our Options object and can be set on suite instantiation or during setup. Opts *ChannelSuiteOpts // contains filtered or unexported fields }
AmqpSuite can be embedded into other suite types to have a connection and channel automatically set up for testing on suite start, and closed on suite shutdown, as well as a number of other helper methods for interacting with a test broker and handling test setup / teardown.
func NewAmqpSuite ¶
func NewAmqpSuite(innerSuite InnerSuite, opts *ChannelSuiteOpts) AmqpSuite
NewAmqpSuite creates a new AmqpSuite for testing with wrapping innerSuite.
func (*AmqpSuite) ChannelConsume ¶
ChannelConsume returns an *amqp.Channel to be used for consuming methods. The returned channel object will be the same each time this methods is called, until ReplaceChannels is called.
func (*AmqpSuite) ChannelConsumeTester ¶
func (amqpSuite *AmqpSuite) ChannelConsumeTester() *amqp.ChannelTesting
ChannelConsumeTester returns *amqp.ChannelTesting object for ChannelConsume with the current suite.T().
func (*AmqpSuite) ChannelPublish ¶
ChannelPublish returns an *amqp.Channel to be used for consuming methods. The returned channel object will be the same each time this methods is called, until ReplaceChannels is called.
func (*AmqpSuite) ChannelPublishTester ¶
func (amqpSuite *AmqpSuite) ChannelPublishTester() *amqp.ChannelTesting
ChannelPublishTester returns *amqp.ChannelTesting object for ChannelPublish with the current suite.T().
func (*AmqpSuite) ConnConsume ¶
func (amqpSuite *AmqpSuite) ConnConsume() *amqp.Connection
ConnConsume returns an *amqp.Connection to be used for consuming methods. The returned connection object will be the same each time this methods is called.
func (*AmqpSuite) ConnPublish ¶
func (amqpSuite *AmqpSuite) ConnPublish() *amqp.Connection
ConnPublish returns an *amqp.Connection to be used for publishing methods. The returned connection object will be the same each time this methods is called.
func (*AmqpSuite) CreateTestExchange ¶
CreateTestExchange creates a basic test exchange on both test channels.
If cleanup is set to true, a cleanup function will be registered with the current suite.T() that will delete the exchange at the end of the test.
func (*AmqpSuite) CreateTestQueue ¶
func (amqpSuite *AmqpSuite) CreateTestQueue( name string, exchange string, exchangeKey string, cleanup bool, ) amqp.Queue
CreateTestQueue creates a basic test queue on both ChannelConsume and ChannelPublish. The created queue can be optionally bound to an exchange (which should have been previously created with CreateTestExchange).
If cleanup is true, then a cleanup function will be registered on the current suite.T() to delete the queues at the end of the test.
func (*AmqpSuite) GetMessage ¶
GetMessage gets a single message, failing the test immediately if there is not a message waiting or the get message fails.
func (*AmqpSuite) PublishMessages ¶
func (amqpSuite *AmqpSuite) PublishMessages( t *testing.T, exchange string, key string, count int, )
PublishMessages publishes messages on the given exchange and Key, waits for confirmations, then returns. Test is failed immediately if any of these steps fails.
Messages bodies are simply the index of the message starting at 0, so publishing 3 messages would result with a message bodies '0', '1', and '2'.
func (*AmqpSuite) ReplaceChannels ¶
func (amqpSuite *AmqpSuite) ReplaceChannels()
ReplaceChannels replace and close the current ChannelConsume and ChannelPublish for fresh ones. Most helpfully used as a cleanup function when persisting the current channels to the next test method is not desirable.
func (*AmqpSuite) SetupSuite ¶
func (amqpSuite *AmqpSuite) SetupSuite()
SetupSuite implements, suite.SetupAllSuite, and sets suite.Opts to NewChannelSuiteOpts if no other opts has been provided.
func (*AmqpSuite) SetupTest ¶
func (amqpSuite *AmqpSuite) SetupTest()
SetupTest implements suite.SetupTestSuite and flushes os.Stdout to help reduce race conditions.
func (*AmqpSuite) TearDownSuite ¶
func (amqpSuite *AmqpSuite) TearDownSuite()
TearDownSuite implements suite.TearDownAllSuite, and closes all open test connections and channels created form this suite's helper methods.
type Assertions ¶
type Assertions interface { Condition(comp assert.Comparison, msgAndArgs ...interface{}) bool Conditionf(comp assert.Comparison, msg string, args ...interface{}) bool Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool DirExists(path string, msgAndArgs ...interface{}) bool DirExistsf(path string, msg string, args ...interface{}) bool ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool Empty(object interface{}, msgAndArgs ...interface{}) bool Emptyf(object interface{}, msg string, args ...interface{}) bool Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool EqualError(theError error, errString string, msgAndArgs ...interface{}) bool EqualErrorf(theError error, errString string, msg string, args ...interface{}) bool EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool Error(err error, msgAndArgs ...interface{}) bool ErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool ErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool ErrorIs(err error, target error, msgAndArgs ...interface{}) bool ErrorIsf(err error, target error, msg string, args ...interface{}) bool Errorf(err error, msg string, args ...interface{}) bool Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool Fail(failureMessage string, msgAndArgs ...interface{}) bool FailNow(failureMessage string, msgAndArgs ...interface{}) bool FailNowf(failureMessage string, msg string, args ...interface{}) bool Failf(failureMessage string, msg string, args ...interface{}) bool False(value bool, msgAndArgs ...interface{}) bool Falsef(value bool, msg string, args ...interface{}) bool FileExists(path string, msgAndArgs ...interface{}) bool FileExistsf(path string, msg string, args ...interface{}) bool Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool HTTPStatusCode(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) bool HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool IsDecreasing(object interface{}, msgAndArgs ...interface{}) bool IsDecreasingf(object interface{}, msg string, args ...interface{}) bool IsIncreasing(object interface{}, msgAndArgs ...interface{}) bool IsIncreasingf(object interface{}, msg string, args ...interface{}) bool IsNonDecreasing(object interface{}, msgAndArgs ...interface{}) bool IsNonDecreasingf(object interface{}, msg string, args ...interface{}) bool IsNonIncreasing(object interface{}, msgAndArgs ...interface{}) bool IsNonIncreasingf(object interface{}, msg string, args ...interface{}) bool IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool JSONEqf(expected string, actual string, msg string, args ...interface{}) bool Len(object interface{}, length int, msgAndArgs ...interface{}) bool Lenf(object interface{}, length int, msg string, args ...interface{}) bool Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool Negative(e interface{}, msgAndArgs ...interface{}) bool Negativef(e interface{}, msg string, args ...interface{}) bool Never(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool Nil(object interface{}, msgAndArgs ...interface{}) bool Nilf(object interface{}, msg string, args ...interface{}) bool NoDirExists(path string, msgAndArgs ...interface{}) bool NoDirExistsf(path string, msg string, args ...interface{}) bool NoError(err error, msgAndArgs ...interface{}) bool NoErrorf(err error, msg string, args ...interface{}) bool NoFileExists(path string, msgAndArgs ...interface{}) bool NoFileExistsf(path string, msg string, args ...interface{}) bool NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool NotEmpty(object interface{}, msgAndArgs ...interface{}) bool NotEmptyf(object interface{}, msg string, args ...interface{}) bool NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool NotEqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool NotErrorIs(err error, target error, msgAndArgs ...interface{}) bool NotErrorIsf(err error, target error, msg string, args ...interface{}) bool NotNil(object interface{}, msgAndArgs ...interface{}) bool NotNilf(object interface{}, msg string, args ...interface{}) bool NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) bool NotPanicsf(f assert.PanicTestFunc, msg string, args ...interface{}) bool NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool NotSame(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool NotZero(i interface{}, msgAndArgs ...interface{}) bool NotZerof(i interface{}, msg string, args ...interface{}) bool Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) bool PanicsWithError(errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) bool PanicsWithErrorf(errString string, f assert.PanicTestFunc, msg string, args ...interface{}) bool PanicsWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) bool PanicsWithValuef(expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) bool Panicsf(f assert.PanicTestFunc, msg string, args ...interface{}) bool Positive(e interface{}, msgAndArgs ...interface{}) bool Positivef(e interface{}, msg string, args ...interface{}) bool Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool True(value bool, msgAndArgs ...interface{}) bool Truef(value bool, msg string, args ...interface{}) bool WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool YAMLEq(expected string, actual string, msgAndArgs ...interface{}) bool YAMLEqf(expected string, actual string, msg string, args ...interface{}) bool Zero(i interface{}, msgAndArgs ...interface{}) bool Zerof(i interface{}, msg string, args ...interface{}) bool }
Assertions is an extracted interface for testify assertions object.
type ChannelSuiteOpts ¶
type ChannelSuiteOpts struct {
// contains filtered or unexported fields
}
ChannelSuiteOpts is used to configure AmqpSuite, which can be embedded into a testify suite.Suite to gain a number of useful testing methods.
func NewChannelSuiteOpts ¶
func NewChannelSuiteOpts() *ChannelSuiteOpts
NewChannelSuiteOpts returns a new ChannelSuiteOpts with default values and the logger set to debug.
func (*ChannelSuiteOpts) WithDialAddress ¶
func (opts *ChannelSuiteOpts) WithDialAddress(amqpURI string) *ChannelSuiteOpts
WithDialAddress configures the address to dial for our test connections. Default: amqp://localhost:57018
func (*ChannelSuiteOpts) WithDialConfig ¶
func (opts *ChannelSuiteOpts) WithDialConfig(config amqp.Config) *ChannelSuiteOpts
WithDialConfig sets the amqp.Config object to use when dialing the test brocker. Default: amqp.DefaultConfig()
type ChannelTesting ¶
type ChannelTesting = amqp.ChannelTesting
ChannelTesting exposes some internals of the Channel type for testing.
type ConnectionTesting ¶
type ConnectionTesting = amqp.ConnectionTesting
ConnectionTesting exposes some internals of the Connection type for testing.
type InnerSuite ¶
type InnerSuite interface { Assertions suite.TestingSuite }
InnerSuite is an interface that can be used to embed an existing testing suite or another helper suite inside of AmqpSuite