Skip to content

Commit

Permalink
Added two simple test, to test the dlq function
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjohansen authored and Gabriel Freites committed Jul 27, 2023
1 parent fcfc5ad commit 114be75
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions pkg/dispatcher/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,7 @@ func (m MockStatsReporter) ReportEventDispatchTime(args *dispatcherstats.ReportA
}

func TestDispatcher_dispatch(t *testing.T) {
//notifyCloseChannel := make(chan *amqp.Error, 1)
//consumeChannel := make(chan amqp.Delivery, 1)
channel := rabbit.RabbitMQChannelMock{
//NotifyCloseChannel: notifyCloseChannel,
//ConsumeChannel: consumeChannel,
}

/*go func() {
for {
select {
case consumer := <-consumeChannel:
log.Fatalf("%+v", consumer)
case notify := <-notifyCloseChannel:
log.Fatalf(notify.Error())
}
}
}()*/
channel := rabbit.RabbitMQChannelMock{}

type fields struct {
BrokerIngressURL string
Expand Down Expand Up @@ -301,6 +285,29 @@ func TestDispatcher_dispatch(t *testing.T) {
},
wantErr: true,
},
{
name: "invalid request dlq",
fields: fields{
Reporter: &MockStatsReporter{},
DLX: true,
},
args: args{
ctx: context.TODO(),
msg: amqp.Delivery{
Acknowledger: &MockAcknowledger{},
ContentType: "application/cloudevents+json",
Headers: amqp.Table{},
Body: []byte(`{"specversion":"1.0","source":"valid-event","id":"valid-id","type":"valid-type"}`),
},
client: MockClient{
request: func(ctx context.Context, m binding.Message, transformers ...binding.Transformer) (binding.Message, error) {
return m, v2.NewHTTPRetriesResult(v2.NewHTTPResult(500, ""), 0, time.Now(), []protocol.Result{})
},
},
channel: &channel,
},
wantErr: true,
},
{
name: "valid event",
fields: fields{
Expand All @@ -322,6 +329,28 @@ func TestDispatcher_dispatch(t *testing.T) {
channel: &channel,
},
},
{
name: "valid event dlq",
fields: fields{
Reporter: &MockStatsReporter{},
DLX: true,
},
args: args{
ctx: context.TODO(),
msg: amqp.Delivery{
Acknowledger: &MockAcknowledger{},
ContentType: "application/cloudevents+json",
Headers: amqp.Table{},
Body: []byte(`{"specversion":"1.0","source":"valid-event","id":"valid-id","type":"valid-type"}`),
},
client: MockClient{
request: func(ctx context.Context, m binding.Message, transformers ...binding.Transformer) (binding.Message, error) {
return m, v2.NewHTTPRetriesResult(v2.NewHTTPResult(200, ""), 0, time.Now(), []protocol.Result{})
},
},
channel: &channel,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 114be75

Please sign in to comment.