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 #6211

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions mmv1/products/cloudscheduler/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
diff_suppress_func: 'authHeaderDiffSuppress'
httpTarget.oidcToken: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'authHeaderDiffSuppress'
httpTarget.uri: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'lastSlashDiffSuppress'
appEngineHttpTarget.headers: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/http_headers.erb'
validation: !ruby/object:Provider::Terraform::Validation
Expand Down
14 changes: 14 additions & 0 deletions mmv1/third_party/terraform/utils/common_diff_suppress.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,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 mmv1/third_party/terraform/utils/common_diff_suppress_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,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": {
megan07 marked this conversation as resolved.
Show resolved Hide resolved
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,
},
edwardmedia marked this conversation as resolved.
Show resolved Hide resolved
}

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)
}
}
}