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.