Documentation ¶
Index ¶
- type Codec
- type EmitHandler
- type T
- type Tester
- func (km *Tester) ClearValues()
- func (km *Tester) Consume(topic string, key string, msg []byte)
- func (km *Tester) ConsumeData(topic string, key string, data []byte)
- func (km *Tester) ConsumeProto(topic string, key string, msg proto.Message)
- func (km *Tester) ConsumeString(topic string, key string, msg string)
- func (km *Tester) ConsumerBuilder() kafka.ConsumerBuilder
- func (km *Tester) ExpectAllEmitted(handler func(topic string, key string, value []byte))
- func (km *Tester) ExpectEmit(topic string, key string, expecter func(value []byte))
- func (km *Tester) Finish(fail bool)
- func (km *Tester) ProducerBuilder() kafka.ProducerBuilder
- func (km *Tester) ReplaceEmitHandler(emitter EmitHandler)
- func (km *Tester) SetCodec(codec Codec) *Tester
- func (km *Tester) SetGroupTableCreator(creator func() (string, []byte))
- func (km *Tester) SetValue(key string, value interface{})
- func (km *Tester) StorageBuilder() storage.Builder
- func (km *Tester) TopicManagerBuilder() kafka.TopicManagerBuilder
- func (km *Tester) ValueForKey(key string) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface { Encode(value interface{}) (data []byte, err error) Decode(data []byte) (value interface{}, err error) }
Codec decodes and encodes from and to []byte
type EmitHandler ¶
EmitHandler abstracts a function that allows to overwrite kafkamock's Emit function to simulate producer errors
type T ¶
type T interface { Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Fatal(a ...interface{}) }
T abstracts the interface we assume from the test case. Will most likely be *testing.T
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
Tester allows interacting with a test processor
func New ¶
New returns a new testprocessor mocking every external service It should be passed as goka.WithTester to goka.NewProcessor. It essentially replaces the storage/consumer/producer/topicmanager with a mock. For example, a normal call to NewProcessor like this
goka.NewProcessor(brokers, group, subscriptions, option_a, option_b, option_c, )
would become in the unit test: tester := tester.New(t) NewProcessor(brokers, group, subscriptions,
option_a, option_b, option_c, WithTester(tester), )
func (*Tester) ClearValues ¶
func (km *Tester) ClearValues()
ClearValues resets everything that might be in the storage by deleting everything using the iterator.
func (*Tester) ConsumeData ¶
ConsumeData simulates a message with a byte slice payload. This is the same as Consume. ConsumeData is a helper function consuming marshalled data. This function is used by ConsumeProto by the test case as well as any emit calls of the processor being tested.
func (*Tester) ConsumeProto ¶
ConsumeProto simulates a message on kafka in a topic with a key.
func (*Tester) ConsumeString ¶
ConsumeString simulates a message with a string payload.
func (*Tester) ConsumerBuilder ¶
func (km *Tester) ConsumerBuilder() kafka.ConsumerBuilder
func (*Tester) ExpectAllEmitted ¶
ExpectAllEmitted calls passed expected-emit-handler function for all emitted values and clears the emitted values
func (*Tester) ExpectEmit ¶
ExpectEmit ensures a message exists in passed topic and key. The message may be inspected/unmarshalled by a passed expecter function.
func (*Tester) Finish ¶
Finish marks the kafkamock that there is no emit to be expected. Set @param fail to true, if kafkamock is supposed to fail the test case in case of remaining emits. Clears the list of emits either case. This should always be called at the end of a test case to make sure no emits of prior test cases are stuck in the list and mess with the test results.
func (*Tester) ProducerBuilder ¶
func (km *Tester) ProducerBuilder() kafka.ProducerBuilder
func (*Tester) ReplaceEmitHandler ¶
func (km *Tester) ReplaceEmitHandler(emitter EmitHandler)
ReplaceEmitHandler replaces the emitter.
func (*Tester) SetGroupTableCreator ¶
SetGroupTableCreator sets a creator for the group table.
func (*Tester) StorageBuilder ¶
func (*Tester) TopicManagerBuilder ¶
func (km *Tester) TopicManagerBuilder() kafka.TopicManagerBuilder
func (*Tester) ValueForKey ¶
ValueForKey attempts to get a value from KafkaMock's storage.