-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dummy handler type for load testing
- Loading branch information
1 parent
029f9a3
commit 8715406
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/nyaruka/courier" | ||
"github.com/nyaruka/courier/handlers" | ||
) | ||
|
||
func init() { | ||
courier.RegisterHandler(newHandler()) | ||
} | ||
|
||
type handler struct { | ||
handlers.BaseHandler | ||
} | ||
|
||
func newHandler() courier.ChannelHandler { | ||
return &handler{handlers.NewBaseHandler(courier.ChannelType("TST"), "Test")} | ||
} | ||
|
||
func (h *handler) Initialize(s courier.Server) error { | ||
h.SetServer(s) | ||
return nil | ||
} | ||
|
||
func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.SendResult, clog *courier.ChannelLog) error { | ||
sendDelayMs := msg.Channel().IntConfigForKey("send_delay_ms", 10) | ||
|
||
time.Sleep(time.Duration(sendDelayMs) * time.Millisecond) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/nyaruka/courier/handlers" | ||
"github.com/nyaruka/courier/test" | ||
"github.com/nyaruka/gocommon/urns" | ||
) | ||
|
||
var sendTestCases = []OutgoingTestCase{ | ||
{ | ||
Label: "Plain Send", | ||
MsgText: "Simple Message ☺", | ||
MsgURN: "tel:+12067791234", | ||
ExpectedRequests: []ExpectedRequest{}, | ||
}, | ||
} | ||
|
||
func TestOutgoing(t *testing.T) { | ||
var channel = test.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56ab", "TST", "+12065551212", "US", | ||
[]string{urns.Phone.Prefix}, | ||
map[string]any{}, | ||
) | ||
RunOutgoingTestCases(t, channel, newHandler(), sendTestCases, nil, nil) | ||
} |