Documentation
¶
Index ¶
- func EncodeBodyProtobuf(body ProtobufEncodable) any
- func ReadBodyFile(bodyFile string) any
- func RegisterTestCaseDefinition(name string, matcher TestCaseMatcher, builder TestCaseBuilder)
- func Run(t *testing.T, suite TestingSuite, extraOptions ...Option)
- func RunTestCaseApplication(t *testing.T, _ TestingSuite, suiteConf *SuiteConfiguration, ...)
- func RunTestCaseInSuite(t *testing.T, suite TestingSuite, testCase func())
- func WithConfigDebug(s *SuiteConfiguration)
- func WithExpectFound(o *subscriberFetcherOptions)
- func WithExpectNotFound(o *subscriberFetcherOptions)
- func WithStreamConsumerRetryDisabled(s *SuiteConfiguration)
- type AppUnderTest
- type DbSubscriberAssertion
- type DbSubscriberFetcher
- type DbSubscriberTestCase
- type DdbSubscriberAssertion
- type DdbSubscriberFetcher
- type DdbSubscriberTestCase
- type HttpserverTestCase
- type HttpserverTestCaseListProvider
- type KvStoreSubscriberAssertion
- type KvstoreSubscriberFetcher
- type KvstoreSubscriberTestCase
- type Option
- func WithClockProvider(clk clock.Clock) Option
- func WithClockProviderAt(datetime string) Option
- func WithComponent(settings env.ComponentBaseSettingsAware) Option
- func WithConfigBytes(bytes []byte, format string) Option
- func WithConfigFile(file string) Option
- func WithConfigMap(settings map[string]any) Option
- func WithConsumer[M any](callback stream.ConsumerCallbackFactory[M]) Option
- func WithConsumers[M any](consumers stream.ConsumerCallbackMap[M]) Option
- func WithContainerExpireAfter(expireAfter time.Duration) Option
- func WithEnvSetup(setups ...func() error) Option
- func WithFixtureSetFactories(factories []fixtures.FixtureSetsFactory, ...) Option
- func WithFixtureSetFactory(factory fixtures.FixtureSetsFactory, ...) Option
- func WithHttpServerShares() Option
- func WithIpReadFromMemory(name string, records map[string]ipread.MemoryRecord) Option
- func WithLogLevel(level string) Option
- func WithLogRecording() Option
- func WithModule(name string, essentialModule kernel.ModuleFactory) Option
- func WithModuleFactory(factory kernel.ModuleMultiFactory) Option
- func WithSharedEnvironment() Option
- func WithSubscribers(transformerFactoryMap mdlsub.TransformerMapTypeVersionFactories) Option
- func WithTestCaseRepeatCount(repeatCount int) Option
- func WithTestCaseWhitelist(testCases ...string) Option
- func WithUntypedConsumer(callback stream.UntypedConsumerCallbackFactory) Option
- func WithoutAutoDetectedComponents(components ...string) Option
- type ProtobufEncodable
- type StreamTestCase
- type StreamTestCaseInput
- type StreamTestCaseOutput
- type StreamTestCaseProvider
- type SubscriberTestCase
- type SubscriptionFetcherOption
- type Suite
- type SuiteConfiguration
- type TestCaseBuilder
- type TestCaseMatcher
- type TestCaseRunner
- type TestingSuite
- type TestingSuiteApiDefinitionsAware
- type TestingSuiteApplicationAware
- type TestingSuiteSetupTestAware
- type TestingSuiteTearDownTestAware
- type ToHttpserverTestCaseList
- type ToStreamTestCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeBodyProtobuf ¶ added in v0.16.0
func EncodeBodyProtobuf(body ProtobufEncodable) any
func ReadBodyFile ¶ added in v0.16.0
func RegisterTestCaseDefinition ¶ added in v0.50.0
func RegisterTestCaseDefinition(name string, matcher TestCaseMatcher, builder TestCaseBuilder)
Register a new test case definition for our test suite. A definition consists of a name, a matcher, and a builder.
- The name of a test case definition is used when reporting errors in case something goes wrong. It has to be unique.
- The matcher is called on every method of a test suite starting with "Test" and should check if the function has the correct argument and return types. If there is any mismatch between the expected and actual types, an error has to be reported. If a matcher from another test case definition matches the method, that definition will be used to execute the test, if no matcher successfully matches the test case, an error is reported.
- The builder creates a runner for the test from the matched method. It might execute the method to get some kind of test case definition (http, consumer, and subscriber test cases work like this) which is later used to run the test. Or the execution of the method might be part of running the actual test (base and application test cases work like this).
This function is not thread safe and should only be called from an init() method.
func RunTestCaseApplication ¶ added in v0.50.0
func RunTestCaseApplication(t *testing.T, _ TestingSuite, suiteConf *SuiteConfiguration, environment *env.Environment, testcase func(aut AppUnderTest), extraOptions ...Option)
func RunTestCaseInSuite ¶ added in v0.50.0
func RunTestCaseInSuite(t *testing.T, suite TestingSuite, testCase func())
func WithConfigDebug ¶ added in v0.26.2
func WithConfigDebug(s *SuiteConfiguration)
func WithExpectFound ¶ added in v0.44.0
func WithExpectFound(o *subscriberFetcherOptions)
func WithExpectNotFound ¶ added in v0.44.0
func WithExpectNotFound(o *subscriberFetcherOptions)
func WithStreamConsumerRetryDisabled ¶ added in v0.26.2
func WithStreamConsumerRetryDisabled(s *SuiteConfiguration)
Types ¶
type AppUnderTest ¶
type DbSubscriberAssertion ¶
type DbSubscriberAssertion func(t *testing.T, fetcher *DbSubscriberFetcher)
type DbSubscriberFetcher ¶
type DbSubscriberFetcher struct {
// contains filtered or unexported fields
}
func (DbSubscriberFetcher) ByPrimaryKey ¶
func (f DbSubscriberFetcher) ByPrimaryKey(key any, model any, options ...SubscriptionFetcherOption)
type DbSubscriberTestCase ¶
type DbSubscriberTestCase struct {
Name string
ModelId string
Version int
Input any
Assert DbSubscriberAssertion
}
type DdbSubscriberAssertion ¶
type DdbSubscriberAssertion func(t *testing.T, fetcher *DdbSubscriberFetcher)
type DdbSubscriberFetcher ¶
type DdbSubscriberFetcher struct {
// contains filtered or unexported fields
}
func (DdbSubscriberFetcher) ByHash ¶
func (f DdbSubscriberFetcher) ByHash(hash any, model any, options ...SubscriptionFetcherOption)
func (DdbSubscriberFetcher) ByHashAndRange ¶
func (f DdbSubscriberFetcher) ByHashAndRange(hash any, rangeValue any, model any, options ...SubscriptionFetcherOption)
type DdbSubscriberTestCase ¶
type HttpserverTestCase ¶ added in v0.15.0
type HttpserverTestCase struct {
Method string
Url string
Headers map[string]string
// Body will be used as the request body. Supported request body data types is `string`,
// `[]byte`, `struct`, `map`, `slice` and `io.Reader`. Body value can be pointer or non-pointer.
// Automatic marshalling for JSON and XML content type, if it is `struct`, `map`, or `slice`.
//
// If you call EncodeBodyProtobuf on your body before assigning it to this field, it will instead be
// encoded using protobuf.
//
// To send the contents of a file, you can use ReadBodyFile and assign the result to this field. The
// test suite will read the file contents and send it as your request.
Body any
// ExpectedStatusCode describes the status code the last response is required to have.
ExpectedStatusCode int
// ExpectedRedirectsToFollow describes the number of redirects we want to follow. It is an error if less redirects
// are performed. More redirects result in the last redirect being returned as the response instead (e.g., if it is
// to some external site or with a protocol different from HTTP(S) like intent://) and do not result in an error.
ExpectedRedirectsToFollow int
// ExpectedResult defines the *type* the final response should be parsed into. You can then access the unmarshalled
// response in response.Result().
ExpectedResult any
// ExpectedErr is compared with the error returned by the HTTP request. Only the error messages have to match.
ExpectedErr error
// Assert allows you to provide an assertion function that can be passed to validate certain post conditions (like
// messages being written to the correct queues).
// It also allows to check that the response carries the correct response body, redirects to the correct
// // location, or has the correct headers set. You don't need to validate the response status here, this is already
// // performed automatically.
Assert func(response *resty.Response) error
// AssertResultFile can be used to read the expected response body from a file, which will be used to check equality
// with the actual response body. If the file name extension is .json, the equality check is done via assert.JSONEq.
AssertResultFile string
}
A HttpserverTestCase should be the return value from your test functions. The following signatures are supported:
func (s* Suite) TestXXX() *HttpserverTestCase func (s* Suite) TestXXX() []*HttpserverTestCase func (s* Suite) TestXXX() ToHttpserverTestCaseList func (s* Suite) TestXXX() map[string]*HttpserverTestCase func (s* Suite) TestXXX() map[string][]*HttpserverTestCase func (s* Suite) TestXXX() map[string]ToHttpserverTestCaseList
func (*HttpserverTestCase) ToTestCaseList ¶ added in v0.31.0
func (c *HttpserverTestCase) ToTestCaseList() []*HttpserverTestCase
type HttpserverTestCaseListProvider ¶ added in v0.31.0
type HttpserverTestCaseListProvider func() []*HttpserverTestCase
A HttpserverTestCaseListProvider allows you to provide a function creating test cases instead of test cases directly. This is useful as it runs after the app has been constructed, fixtures loaded, etc.
func (HttpserverTestCaseListProvider) ToTestCaseList ¶ added in v0.31.0
func (f HttpserverTestCaseListProvider) ToTestCaseList() []*HttpserverTestCase
type KvStoreSubscriberAssertion ¶
type KvStoreSubscriberAssertion func(t *testing.T, fetcher *KvstoreSubscriberFetcher)
type KvstoreSubscriberFetcher ¶
type KvstoreSubscriberFetcher struct {
// contains filtered or unexported fields
}
func (KvstoreSubscriberFetcher) Get ¶
func (f KvstoreSubscriberFetcher) Get(key any, model mdlsub.Model, options ...SubscriptionFetcherOption)
type KvstoreSubscriberTestCase ¶
type KvstoreSubscriberTestCase struct {
Name string
ModelId string
Input any
Version int
Assert KvStoreSubscriberAssertion
}
type Option ¶
type Option func(s *SuiteConfiguration)
func WithClockProvider ¶
func WithClockProviderAt ¶
func WithComponent ¶
func WithComponent(settings env.ComponentBaseSettingsAware) Option
func WithConfigBytes ¶ added in v0.56.0
func WithConfigFile ¶
func WithConfigMap ¶
func WithConsumer ¶
func WithConsumer[M any](callback stream.ConsumerCallbackFactory[M]) Option
func WithConsumers ¶ added in v0.50.0
func WithConsumers[M any](consumers stream.ConsumerCallbackMap[M]) Option
func WithEnvSetup ¶
func WithFixtureSetFactories ¶ added in v0.24.0
func WithFixtureSetFactories(factories []fixtures.FixtureSetsFactory, postProcessorFactories ...fixtures.PostProcessorFactory) Option
func WithFixtureSetFactory ¶ added in v0.36.0
func WithFixtureSetFactory(factory fixtures.FixtureSetsFactory, postProcessorFactories ...fixtures.PostProcessorFactory) Option
func WithHttpServerShares ¶ added in v0.15.0
func WithHttpServerShares() Option
func WithIpReadFromMemory ¶
func WithIpReadFromMemory(name string, records map[string]ipread.MemoryRecord) Option
func WithLogLevel ¶
func WithLogRecording ¶ added in v0.18.1
func WithLogRecording() Option
func WithModule ¶
func WithModule(name string, essentialModule kernel.ModuleFactory) Option
func WithModuleFactory ¶
func WithModuleFactory(factory kernel.ModuleMultiFactory) Option
func WithSharedEnvironment ¶
func WithSharedEnvironment() Option
func WithSubscribers ¶
func WithSubscribers(transformerFactoryMap mdlsub.TransformerMapTypeVersionFactories) Option
func WithTestCaseRepeatCount ¶
WithTestCaseRepeatCount repeats the whole test suite the given number of times. This can be useful if a problem doesn't happen on every run (e.g., because it is timing dependent).
func WithTestCaseWhitelist ¶
WithTestCaseWhitelist returns an option which only runs the tests contained in the given whitelist. A test not in the whitelist is skipped instead, allowing you to easily run a single test (e.g., for debugging).
func WithUntypedConsumer ¶ added in v0.41.0
func WithUntypedConsumer(callback stream.UntypedConsumerCallbackFactory) Option
type ProtobufEncodable ¶ added in v0.16.0
type StreamTestCase ¶
type StreamTestCase struct {
Input map[string][]StreamTestCaseInput
Output map[string][]StreamTestCaseOutput
Assert func() error
}
func (*StreamTestCase) ToTestCase ¶ added in v0.31.0
func (c *StreamTestCase) ToTestCase() *StreamTestCase
type StreamTestCaseInput ¶
type StreamTestCaseOutput ¶
type StreamTestCaseProvider ¶ added in v0.31.0
type StreamTestCaseProvider func() *StreamTestCase
func (StreamTestCaseProvider) ToTestCase ¶ added in v0.31.0
func (f StreamTestCaseProvider) ToTestCase() *StreamTestCase
type SubscriberTestCase ¶
type SubscriberTestCase interface {
GetName() string
GetModelId() string
GetInput() any
GetVersion() int
}
func DbTestCase ¶
func DbTestCase(testCase DbSubscriberTestCase) (SubscriberTestCase, error)
func DdbTestCase ¶
func DdbTestCase(testCase DdbSubscriberTestCase) (SubscriberTestCase, error)
func KvstoreTestCase ¶
func KvstoreTestCase(testCase KvstoreSubscriberTestCase) (SubscriberTestCase, error)
type SubscriptionFetcherOption ¶ added in v0.44.0
type SubscriptionFetcherOption func(*subscriberFetcherOptions)
type Suite ¶
type Suite struct {
*assert.Assertions
// contains filtered or unexported fields
}
func (*Suite) Env ¶
func (s *Suite) Env() *env.Environment
func (*Suite) FailIfError ¶ added in v0.20.0
func (*Suite) Require ¶ added in v0.55.0
func (s *Suite) Require() *require.Assertions
func (*Suite) SetEnv ¶
func (s *Suite) SetEnv(env *env.Environment)
type SuiteConfiguration ¶ added in v0.50.0
type SuiteConfiguration struct {
// contains filtered or unexported fields
}
type TestCaseBuilder ¶ added in v0.50.0
type TestCaseBuilder func(suite TestingSuite, method reflect.Method) (TestCaseRunner, error)
type TestCaseMatcher ¶ added in v0.50.0
type TestCaseMatcher func(suite TestingSuite, method reflect.Method) error
type TestCaseRunner ¶ added in v0.50.0
type TestCaseRunner func(t *testing.T, suite TestingSuite, suiteConf *SuiteConfiguration, environment *env.Environment)
type TestingSuite ¶
type TestingSuite interface {
Env() *env.Environment
SetEnv(environment *env.Environment)
SetT(t *testing.T)
T() *testing.T
SetupSuite() []Option
}
type TestingSuiteApiDefinitionsAware ¶
type TestingSuiteApiDefinitionsAware interface {
SetupApiDefinitions() httpserver.Definer
}
type TestingSuiteApplicationAware ¶
type TestingSuiteApplicationAware interface {
SetupApplication() error
}
type TestingSuiteSetupTestAware ¶
type TestingSuiteSetupTestAware interface {
SetupTest() error
}
type TestingSuiteTearDownTestAware ¶
type TestingSuiteTearDownTestAware interface {
TearDownTest() error
}
type ToHttpserverTestCaseList ¶ added in v0.31.0
type ToHttpserverTestCaseList interface {
ToTestCaseList() []*HttpserverTestCase
}
A ToHttpserverTestCaseList can be converted into a list of test cases. You can use this interface instead of concrete test case types when declaring test cases.
type ToStreamTestCase ¶ added in v0.31.0
type ToStreamTestCase interface {
ToTestCase() *StreamTestCase
}