Skip to content

Commit

Permalink
worker: test: use constructor for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
turtleDev committed Sep 3, 2024
1 parent fb55724 commit 873be45
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package worker

import (
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -35,12 +34,9 @@ func TestWorker(t *testing.T) {
t.Run("Should publish messages on bufferChannel to kafka", func(t *testing.T) {
kp := mockKafkaPublisher{}
bc := make(chan collector.CollectRequest, 2)
worker := Pool{
Size: 1,
EventsChannel: bc,
producer: &kp,
wg: sync.WaitGroup{},
}
worker := CreateWorkerPool(
1, bc, &kp,
)
worker.StartWorkers()

kp.On("ProduceBulk", mock.Anything, mock.Anything, mock.Anything).Return(nil).Twice()
Expand All @@ -59,12 +55,9 @@ func TestWorker(t *testing.T) {
defer kp.AssertExpectations(t)

q := make(chan collector.CollectRequest, 1)
worker := Pool{
Size: 1,
EventsChannel: q,
producer: &kp,
wg: sync.WaitGroup{},
}
worker := CreateWorkerPool(
1, q, &kp,
)
worker.StartWorkers()

ackMock := &mockAck{}
Expand Down Expand Up @@ -93,12 +86,9 @@ func TestWorker(t *testing.T) {
defer kp.AssertExpectations(t)

q := make(chan collector.CollectRequest, 2)
worker := Pool{
Size: 1,
EventsChannel: q,
producer: &kp,
wg: sync.WaitGroup{},
}
worker := CreateWorkerPool(
1, q, &kp,
)
worker.StartWorkers()

ackMock := &mockAck{}
Expand All @@ -117,12 +107,9 @@ func TestWorker(t *testing.T) {
kp := mockKafkaPublisher{}
bc := make(chan collector.CollectRequest, 2)

worker := Pool{
Size: 1,
EventsChannel: bc,
producer: &kp,
wg: sync.WaitGroup{},
}
worker := CreateWorkerPool(
1, bc, &kp,
)
worker.StartWorkers()
kp.On("ProduceBulk", mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(3).After(3 * time.Millisecond)
kp.On("Name").Return("kafka")
Expand Down

0 comments on commit 873be45

Please sign in to comment.