Skip to content

Commit

Permalink
supress diff when user name has multi spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
imjaroiswebdev committed Jan 26, 2024
1 parent b26ae38 commit 661810c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pagerduty/resource_pagerduty_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func testSweepUser(region string) error {
}

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

resource.Test(t, resource.TestCase{
Expand Down
5 changes: 4 additions & 1 deletion pagerduty/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"math"
"reflect"
"regexp"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -82,7 +83,9 @@ func parseRFC3339Time(k, oldTime, newTime string) (time.Time, time.Time, error)
}

func suppressLeadTrailSpaceDiff(k, old, new string, d *schema.ResourceData) bool {
return old == strings.TrimSpace(new)
trimmedInput := strings.TrimSpace(new)
repeatedSpaceMatcher := regexp.MustCompile(`\s+`)
return old == repeatedSpaceMatcher.ReplaceAllLiteralString(trimmedInput, " ")
}

func suppressCaseDiff(k, old, new string, d *schema.ResourceData) bool {
Expand Down

0 comments on commit 661810c

Please sign in to comment.