Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed diff on last slash of uri #12027

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6211.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudscheduler: fixed a diff on the last slash of uri on `google_cloud_scheduler_job`
```
14 changes: 14 additions & 0 deletions google/common_diff_suppress.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,17 @@ func compareOptionalSubnet(_, old, new string, _ *schema.ResourceData) bool {
// otherwise compare as self links
return compareSelfLinkOrResourceName("", old, new, nil)
}

// Suppress diffs in below cases
// "https://hello-rehvs75zla-uc.a.run.app/" -> "https://hello-rehvs75zla-uc.a.run.app"
// "https://hello-rehvs75zla-uc.a.run.app" -> "https://hello-rehvs75zla-uc.a.run.app/"
func lastSlashDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
if last := len(new) - 1; last >= 0 && new[last] == '/' {
new = new[:last]
}

if last := len(old) - 1; last >= 0 && old[last] == '/' {
old = old[:last]
}
return new == old
}
39 changes: 39 additions & 0 deletions google/common_diff_suppress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,42 @@ func TestDurationDiffSuppress(t *testing.T) {
}
}
}

func TestLastSlashDiffSuppress(t *testing.T) {
cases := map[string]struct {
Old, New string
ExpectDiffSuppress bool
}{
"slash to no slash": {
Old: "https://hello-rehvs75zla-uc.a.run.app/",
New: "https://hello-rehvs75zla-uc.a.run.app",
ExpectDiffSuppress: true,
},
"no slash to slash": {
Old: "https://hello-rehvs75zla-uc.a.run.app",
New: "https://hello-rehvs75zla-uc.a.run.app/",
ExpectDiffSuppress: true,
},
"slash to slash": {
Old: "https://hello-rehvs75zla-uc.a.run.app/",
New: "https://hello-rehvs75zla-uc.a.run.app/",
ExpectDiffSuppress: true,
},
"no slash to no slash": {
Old: "https://hello-rehvs75zla-uc.a.run.app",
New: "https://hello-rehvs75zla-uc.a.run.app",
ExpectDiffSuppress: true,
},
"different domains": {
Old: "https://x.a.run.app/",
New: "https://y.a.run.app",
ExpectDiffSuppress: false,
},
}

for tn, tc := range cases {
if lastSlashDiffSuppress("uri", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress)
}
}
}
7 changes: 4 additions & 3 deletions google/resource_cloud_scheduler_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ send a request to the targeted url`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Required: true,
Description: `The full URI path that the request will be sent to.`,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: lastSlashDiffSuppress,
Description: `The full URI path that the request will be sent to.`,
},
"body": {
Type: schema.TypeString,
Expand Down