Skip to content

Commit

Permalink
Merge pull request #389 from hashicorp/jspiker/ms-teams
Browse files Browse the repository at this point in the history
Add Microsoft Teams notification destination type
  • Loading branch information
JarrettSpiker committed Jun 8, 2022
2 parents b0c0edc + 515f37b commit 26d3401
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,9 @@
# v1.2.0 (Unreleased)
# v1.3.0 (Unreleased)

## Enhancements
* Adds support for Microsoft Teams notification configuration by @JarrettSpiker [#398](https://github.com/hashicorp/go-tfe/pull/389)

# v1.2.0

## Enhancements
* Adds support for reading current state version outputs to StateVersionOutputs, which can be useful for reading outputs when users don't have the necessary permissions to read the entire state by @brandonc [#370](https://github.com/hashicorp/go-tfe/pull/370)
Expand Down
12 changes: 8 additions & 4 deletions notification_configuration.go
Expand Up @@ -59,9 +59,10 @@ type NotificationDestinationType string

// List of available notification destination types.
const (
NotificationDestinationTypeEmail NotificationDestinationType = "email"
NotificationDestinationTypeGeneric NotificationDestinationType = "generic"
NotificationDestinationTypeSlack NotificationDestinationType = "slack"
NotificationDestinationTypeEmail NotificationDestinationType = "email"
NotificationDestinationTypeGeneric NotificationDestinationType = "generic"
NotificationDestinationTypeSlack NotificationDestinationType = "slack"
NotificationDestinationTypeMicrosoftTeams NotificationDestinationType = "microsoft-teams"
)

// NotificationConfigurationList represents a list of Notification
Expand Down Expand Up @@ -319,7 +320,10 @@ func (o NotificationConfigurationCreateOptions) valid() error {
return ErrInvalidNotificationTrigger
}

if *o.DestinationType == NotificationDestinationTypeGeneric || *o.DestinationType == NotificationDestinationTypeSlack {
if *o.DestinationType == NotificationDestinationTypeGeneric ||
*o.DestinationType == NotificationDestinationTypeSlack ||
*o.DestinationType == NotificationDestinationTypeMicrosoftTeams {

if o.URL == nil {
return ErrRequiredURL
}
Expand Down
26 changes: 26 additions & 0 deletions notification_configuration_integration_test.go
Expand Up @@ -128,6 +128,32 @@ func TestNotificationConfigurationCreate(t *testing.T) {
assert.Equal(t, err, ErrRequiredURL)
})

t.Run("without a required value URL when destination type is slack", func(t *testing.T) {
options := NotificationConfigurationCreateOptions{
DestinationType: NotificationDestination(NotificationDestinationTypeSlack),
Enabled: Bool(false),
Name: String(randomString(t)),
Triggers: []NotificationTriggerType{NotificationTriggerCreated},
}

nc, err := client.NotificationConfigurations.Create(ctx, wTest.ID, options)
assert.Nil(t, nc)
assert.Equal(t, err, ErrRequiredURL)
})

t.Run("without a required value URL when destination type is MS Teams", func(t *testing.T) {
options := NotificationConfigurationCreateOptions{
DestinationType: NotificationDestination(NotificationDestinationTypeMicrosoftTeams),
Enabled: Bool(false),
Name: String(randomString(t)),
Triggers: []NotificationTriggerType{NotificationTriggerCreated},
}

nc, err := client.NotificationConfigurations.Create(ctx, wTest.ID, options)
assert.Nil(t, nc)
assert.Equal(t, err, ErrRequiredURL)
})

t.Run("without a valid workspace", func(t *testing.T) {
nc, err := client.NotificationConfigurations.Create(ctx, badIdentifier, NotificationConfigurationCreateOptions{})
assert.Nil(t, nc)
Expand Down

0 comments on commit 26d3401

Please sign in to comment.