Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request PagerDuty#316 from stmcallister/rp-responder
Browse files Browse the repository at this point in the history
Response Play Responder to Optional and User Email to Case Insensitive
  • Loading branch information
Scott McAllister authored Mar 26, 2021
2 parents f3b1b70 + 0117c69 commit 5318a15
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pagerduty/resource_pagerduty_response_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func resourcePagerDutyResponsePlay() *schema.Resource {
},
"responder": {
Type: schema.TypeList,
Required: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Expand Down
12 changes: 4 additions & 8 deletions pagerduty/resource_pagerduty_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ func resourcePagerDutyUser() *schema.Resource {
Type: schema.TypeString,
Required: true,
// Suppress the diff shown if there are leading or trailing spaces
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == strings.TrimSpace(new) {
return true
}
return false
},
DiffSuppressFunc: suppressLeadTrailSpaceDiff,
},

"email": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppressCaseDiff,
},

"color": {
Expand Down
7 changes: 4 additions & 3 deletions pagerduty/resource_pagerduty_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func testSweepUser(region string) error {

func TestAccPagerDutyUser_Basic(t *testing.T) {
username := fmt.Sprintf("tf-%s", acctest.RandString(5))
usernameSpaces := " " + username + " "
usernameUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5))
email := fmt.Sprintf("%s@foo.com", username)
email := fmt.Sprintf("%s@Foo.com", username)
emailUpdated := fmt.Sprintf("%s@foo.com", usernameUpdated)

resource.Test(t, resource.TestCase{
Expand All @@ -64,13 +65,13 @@ func TestAccPagerDutyUser_Basic(t *testing.T) {
CheckDestroy: testAccCheckPagerDutyUserDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyUserConfig(username, email),
Config: testAccCheckPagerDutyUserConfig(usernameSpaces, email),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserExists("pagerduty_user.foo"),
resource.TestCheckResourceAttr(
"pagerduty_user.foo", "name", username),
resource.TestCheckResourceAttr(
"pagerduty_user.foo", "email", email),
"pagerduty_user.foo", "email", strings.ToLower(email)),
resource.TestCheckResourceAttr(
"pagerduty_user.foo", "color", "green"),
resource.TestCheckResourceAttr(
Expand Down
9 changes: 9 additions & 0 deletions pagerduty/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -42,6 +43,14 @@ func suppressRFC3339Diff(k, oldTime, newTime string, d *schema.ResourceData) boo
return oldT.Equal(newT)
}

func suppressLeadTrailSpaceDiff(k, old, new string, d *schema.ResourceData) bool {
return old == strings.TrimSpace(new)
}

func suppressCaseDiff(k, old, new string, d *schema.ResourceData) bool {
return old == strings.ToLower(new)
}

// Validate a value against a set of possible values
func validateValueFunc(values []string) schema.SchemaValidateFunc {
return func(v interface{}, k string) (we []string, errors []error) {
Expand Down

0 comments on commit 5318a15

Please sign in to comment.