Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Simple way of creating a message for testing purpose #51

Open
asdine opened this issue Oct 1, 2019 · 0 comments
Open

Simple way of creating a message for testing purpose #51

asdine opened this issue Oct 1, 2019 · 0 comments

Comments

@asdine
Copy link
Contributor

asdine commented Oct 1, 2019

It is a bit difficult to create a consumer.Message or producer.Message the first time when testing our handlers. It would be nice if we could have some kind of helper method to do that.

Currently, we need to do something like this:

var m consumer.Message
m.Body = codec.JSONDecoder([]byte(`{"foo":"bar"}`))
m.Headers = make(map[string]string)
m.ID = strconv.Itoa(rand.Intn(1e5))
m.ProducedAt = time.Now().UTC()
key, err := codec.Int64().Encode(i)
require.NoError(t, err)
m.Key = codec.Int64Decoder(key)

err := c.HandleMessage(&m)
require.NoError(t, err)

This is not a lot of lines but I had to browse the source code and deal with a panic (the nil headers) to be able to write them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant