Skip to content

Commit

Permalink
Expose TeamsMessage interface to support mocking
Browse files Browse the repository at this point in the history
Export the `TeamsMessage` interface type to better support
abstracting/mocking the functionality of this library by
dependent projects.

The fields of the interface are intentionally not exported so
as to help prevent future changes/improvements from breaking
client code.

This change is considered a non-breaking change as the support
for creating message types compliant with this interface is
unchanged.

refs GH-285
  • Loading branch information
atc0005 committed Aug 7, 2024
1 parent ababe23 commit 1c810df
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 1c810df

Please sign in to comment.