Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartboyd119 committed Jul 24, 2024
1 parent 3440ad8 commit e3ced13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
17 changes: 7 additions & 10 deletions test/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
"github.com/golang/mock/gomock"
)

var (
topicName = "orange"
NoopOnDone = func() {}
const (
topicName = "orange"
)

func TestWork_Run_FailsWithLogsWhenFailedToGetReader(t *testing.T) {
Expand Down Expand Up @@ -1140,7 +1139,7 @@ func TestWork_LifecycleHooksCalledForEachItem_Reader(t *testing.T) {
l := zkafka.NoopLogger{}

numMsgs := 5
msgs := getFakeMessages(topicName, numMsgs, struct{ name string }{name: "arish"}, &zfmt.JSONFormatter{}, NoopOnDone)
msgs := getFakeMessages(topicName, numMsgs, struct{ name string }{name: "arish"}, &zfmt.JSONFormatter{})
r := zkafka_mocks.NewMockReader(ctrl)

gomock.InOrder(
Expand Down Expand Up @@ -1207,7 +1206,7 @@ func TestWork_LifecycleHooksPostReadCanUpdateContext(t *testing.T) {
l := zkafka.NoopLogger{}

numMsgs := 1
msgs := getFakeMessages(topicName, numMsgs, "lydia", &zfmt.JSONFormatter{}, NoopOnDone)
msgs := getFakeMessages(topicName, numMsgs, "lydia", &zfmt.JSONFormatter{})
r := zkafka_mocks.NewMockReader(ctrl)

gomock.InOrder(
Expand Down Expand Up @@ -1268,7 +1267,7 @@ func TestWork_LifecycleHooksPostReadErrorDoesntHaltProcessing(t *testing.T) {
l := zkafka.NoopLogger{}

numMsgs := 1
msgs := getFakeMessages(topicName, numMsgs, "lydia", &zfmt.JSONFormatter{}, NoopOnDone)
msgs := getFakeMessages(topicName, numMsgs, "lydia", &zfmt.JSONFormatter{})
r := zkafka_mocks.NewMockReader(ctrl)

gomock.InOrder(
Expand Down Expand Up @@ -1325,7 +1324,7 @@ func TestWork_LifecycleHooksCalledForEachItem(t *testing.T) {

l := zkafka.NoopLogger{}
numMsgs := 5
msgs := getFakeMessages(topicName, numMsgs, struct{ name string }{name: "arish"}, &zfmt.JSONFormatter{}, NoopOnDone)
msgs := getFakeMessages(topicName, numMsgs, struct{ name string }{name: "arish"}, &zfmt.JSONFormatter{})
r := zkafka_mocks.NewMockReader(ctrl)

gomock.InOrder(
Expand Down Expand Up @@ -2146,17 +2145,15 @@ func pollWait(f func() bool, opts pollOpts) {
}
}

func getFakeMessages(topic string, numMsgs int, value any, formatter zfmt.Formatter, doneFunc func()) []*zkafka.Message {
func getFakeMessages(topic string, numMsgs int, value any, formatter zfmt.Formatter) []*zkafka.Message {
msgs := make([]*zkafka.Message, numMsgs)
wrapperFunc := func(c context.Context) { doneFunc() }

for i := 0; i < numMsgs; i++ {
key := fmt.Sprint(i)
msgs[i] = zkafka.GetMsgFromFake(&zkafka.FakeMessage{
Key: &key,
ValueData: value,
Fmt: formatter,
DoneFunc: wrapperFunc,
})
msgs[i].Topic = topic
}
Expand Down
1 change: 1 addition & 0 deletions testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func GetMsgFromFake(msg *FakeMessage) *Message {
val = msg.Value
}
if msg.ValueData != nil {
//nolint:errcheck // To simplify this helper function's api, we'll suppress marshalling errors.
val, _ = msg.Fmt.Marshall(msg.ValueData)
}
return &Message{
Expand Down

0 comments on commit e3ced13

Please sign in to comment.