tester

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

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

type EmitHandler func(topic string, key string, value []byte) *kafka.Promise

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

func New(t T) *Tester

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) Consume

func (km *Tester) Consume(topic string, key string, msg []byte)

Consume simulates a message with a byte slice payload.

func (*Tester) ConsumeData

func (km *Tester) ConsumeData(topic string, key string, data []byte)

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

func (km *Tester) ConsumeProto(topic string, key string, msg proto.Message)

ConsumeProto simulates a message on kafka in a topic with a key.

func (*Tester) ConsumeString

func (km *Tester) ConsumeString(topic string, key string, msg string)

ConsumeString simulates a message with a string payload.

func (*Tester) ConsumerBuilder

func (km *Tester) ConsumerBuilder() kafka.ConsumerBuilder

func (*Tester) ExpectAllEmitted

func (km *Tester) ExpectAllEmitted(handler func(topic string, key string, value []byte))

ExpectAllEmitted calls passed expected-emit-handler function for all emitted values and clears the emitted values

func (*Tester) ExpectEmit

func (km *Tester) ExpectEmit(topic string, key string, expecter func(value []byte))

ExpectEmit ensures a message exists in passed topic and key. The message may be inspected/unmarshalled by a passed expecter function.

func (*Tester) Finish

func (km *Tester) Finish(fail bool)

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) SetCodec

func (km *Tester) SetCodec(codec Codec) *Tester

SetCodec sets the codec for the group table.

func (*Tester) SetGroupTableCreator

func (km *Tester) SetGroupTableCreator(creator func() (string, []byte))

SetGroupTableCreator sets a creator for the group table.

func (*Tester) SetValue

func (km *Tester) SetValue(key string, value interface{})

SetValue sets a value in the storage.

func (*Tester) StorageBuilder

func (km *Tester) StorageBuilder() storage.Builder

func (*Tester) TopicManagerBuilder

func (km *Tester) TopicManagerBuilder() kafka.TopicManagerBuilder

func (*Tester) ValueForKey

func (km *Tester) ValueForKey(key string) interface{}

ValueForKey attempts to get a value from KafkaMock's storage.

Jump to

Keyboard shortcuts

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