Skip to content

Commit

Permalink
Merge pull request #291 from atc0005/i285-expose-TeamsMessage-interface
Browse files Browse the repository at this point in the history
Expose `TeamsMessage` interface to support mocking
  • Loading branch information
atc0005 authored Aug 8, 2024
2 parents 14d0f67 + 8b7707c commit adbaed0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ type messageValidator interface {
Validate() error
}

// teamsMessage is the interface shared by all supported message formats for
// TeamsMessage is the interface shared by all supported message formats for
// submission to a Microsoft Teams channel.
type teamsMessage interface {
type TeamsMessage interface {
messagePreparer
messageValidator

Expand Down Expand Up @@ -301,7 +301,7 @@ func (c *teamsClient) Send(webhookURL string, webhookMessage MessageCard) error

// Send is a wrapper function around the SendWithContext method in order to
// provide backwards compatibility.
func (c *TeamsClient) Send(webhookURL string, message teamsMessage) error {
func (c *TeamsClient) Send(webhookURL string, message TeamsMessage) error {
// Create context that can be used to emulate existing timeout behavior.
ctx, cancel := context.WithTimeout(context.Background(), DefaultWebhookSendTimeout)
defer cancel()
Expand All @@ -321,7 +321,7 @@ func (c *teamsClient) SendWithContext(ctx context.Context, webhookURL string, we
// SendWithContext submits a given message to a Microsoft Teams channel using
// the provided webhook URL. The http client request honors the cancellation
// or timeout of the provided context.
func (c *TeamsClient) SendWithContext(ctx context.Context, webhookURL string, message teamsMessage) error {
func (c *TeamsClient) SendWithContext(ctx context.Context, webhookURL string, message TeamsMessage) error {
return sendWithContext(ctx, c, webhookURL, message)
}

Expand All @@ -337,7 +337,7 @@ func (c *teamsClient) SendWithRetry(ctx context.Context, webhookURL string, webh
// SendWithRetry provides message retry support when submitting messages to a
// Microsoft Teams channel. The caller is responsible for providing the
// desired context timeout, the number of retries and retries delay.
func (c *TeamsClient) SendWithRetry(ctx context.Context, webhookURL string, message teamsMessage, retries int, retriesDelay int) error {
func (c *TeamsClient) SendWithRetry(ctx context.Context, webhookURL string, message TeamsMessage, retries int, retriesDelay int) error {
return sendWithRetry(ctx, c, webhookURL, message, retries, retriesDelay)
}

Expand Down Expand Up @@ -499,7 +499,7 @@ func (c *TeamsClient) ValidateWebhook(webhookURL string) error {
// sendWithContext submits a given message to a Microsoft Teams channel using
// the provided webhook URL and client. The http client request honors the
// cancellation or timeout of the provided context.
func sendWithContext(ctx context.Context, client MessageSender, webhookURL string, message teamsMessage) error {
func sendWithContext(ctx context.Context, client MessageSender, webhookURL string, message TeamsMessage) error {
logger.Printf("sendWithContext: Webhook message received: %#v\n", message)

if err := client.ValidateWebhook(webhookURL); err != nil {
Expand Down Expand Up @@ -563,7 +563,7 @@ func sendWithContext(ctx context.Context, client MessageSender, webhookURL strin
// sendWithRetry provides message retry support when submitting messages to a
// Microsoft Teams channel. The caller is responsible for providing the
// desired context timeout, the number of retries and retries delay.
func sendWithRetry(ctx context.Context, client MessageSender, webhookURL string, message teamsMessage, retries int, retriesDelay int) error {
func sendWithRetry(ctx context.Context, client MessageSender, webhookURL string, message TeamsMessage, retries int, retriesDelay int) error {
var result error

// initial attempt + number of specified retries
Expand Down

0 comments on commit adbaed0

Please sign in to comment.