Skip to content

Commit

Permalink
Merge pull request #804 from nyaruka/test_error_by_msg_text
Browse files Browse the repository at this point in the history
TST handler should error sends with msg text \error
  • Loading branch information
rowanseymour authored Nov 18, 2024
2 parents 1b20423 + 15cc1e1 commit 9e07701
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion handlers/test/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"context"
"strings"
"time"

"github.com/nyaruka/courier"
Expand Down Expand Up @@ -32,7 +33,7 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen

time.Sleep(time.Duration(sendDelayMs) * time.Millisecond)

if random.IntN(100) < errorPercent {
if random.IntN(100) < errorPercent || strings.Contains(msg.Text(), "\\error") {
return courier.ErrConnectionFailed
}

Expand Down
12 changes: 10 additions & 2 deletions handlers/test/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package test
import (
"testing"

"github.com/nyaruka/courier"
. "github.com/nyaruka/courier/handlers"
"github.com/nyaruka/courier/test"
"github.com/nyaruka/gocommon/random"
Expand All @@ -11,11 +12,18 @@ import (

var sendTestCases = []OutgoingTestCase{
{
Label: "Plain Send",
MsgText: "Simple Message ☺",
Label: "Normal send",
MsgText: "Hi here",
MsgURN: "tel:+12067791234",
ExpectedRequests: []ExpectedRequest{},
},
{
Label: "Error send",
MsgText: "Hi here \\error",
MsgURN: "tel:+12067791234",
ExpectedRequests: []ExpectedRequest{},
ExpectedError: courier.ErrConnectionFailed,
},
}

func TestOutgoing(t *testing.T) {
Expand Down

0 comments on commit 9e07701

Please sign in to comment.