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

Simple way of creating a message for testing purpose #51

@asdine

Description

@asdine

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions