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

Add safe self_link comparison to compute DS tests #1331

Merged
merged 1 commit into from
Nov 5, 2019
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
5 changes: 4 additions & 1 deletion google-beta/data_source_google_compute_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func testAccDataSourceComputeAddressCheck(data_source_name string, resource_name
rs_attr := rs.Primary.Attributes

address_attrs_to_test := []string{
"self_link",
"name",
"address",
}
Expand All @@ -123,6 +122,10 @@ func testAccDataSourceComputeAddressCheck(data_source_name string, resource_name
}
}

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}

if ds_attr["status"] != "RESERVED" {
return fmt.Errorf("status is %s; want RESERVED", ds_attr["status"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func testAccDataSourceGoogleForwardingRuleCheck(data_source_name string, resourc
rs_attr := rs.Primary.Attributes
forwarding_rule_attrs_to_test := []string{
"id",
"self_link",
"name",
"description",
"region",
Expand All @@ -70,6 +69,11 @@ func testAccDataSourceGoogleForwardingRuleCheck(data_source_name string, resourc
)
}
}

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}

return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func testAccDataSourceComputeGlobalAddressCheck(data_source_name string, resourc
rs_attr := rs.Primary.Attributes

address_attrs_to_test := []string{
"self_link",
"name",
"address",
}
Expand All @@ -63,6 +62,10 @@ func testAccDataSourceComputeGlobalAddressCheck(data_source_name string, resourc
}
}

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}

if ds_attr["status"] != "RESERVED" {
return fmt.Errorf("status is %s; want RESERVED", ds_attr["status"])
}
Expand Down
9 changes: 7 additions & 2 deletions google-beta/data_source_google_compute_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func testAccDataSourceCheckPublicImage() resource.TestCheckFunc {

ds_attr := ds.Primary.Attributes
attrs_to_test := map[string]string{
"self_link": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20171129",
"family": "debian-9",
"family": "debian-9",
}

for attr, expect_value := range attrs_to_test {
Expand All @@ -66,6 +65,12 @@ func testAccDataSourceCheckPublicImage() resource.TestCheckFunc {
}
}

selfLink := "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20171129"

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], selfLink, nil) && ds_attr["self_link"] != selfLink {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], selfLink)
}

return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func testAccCheckDataSourceGoogleComputeInstanceGroup(dataSourceName string) res
"project",
"description",
"network",
"self_link",
"size",
}

Expand All @@ -99,6 +98,10 @@ func testAccCheckDataSourceGoogleComputeInstanceGroup(dataSourceName string) res
}
}

if !compareSelfLinkOrResourceName("", dsAttrs["self_link"], rsAttrs["self_link"], nil) && dsAttrs["self_link"] != rsAttrs["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", dsAttrs["self_link"], rsAttrs["self_link"])
}

dsNamedPortsCount, ok := dsAttrs["named_port.#"]
if !ok {
return errors.New("can't find 'named_port' attribute in data source")
Expand Down
6 changes: 5 additions & 1 deletion google-beta/data_source_google_compute_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func testAccDataSourceGoogleNetworkCheck(data_source_name string, resource_name
rs_attr := rs.Primary.Attributes
network_attrs_to_test := []string{
"id",
"self_link",
"name",
"description",
}
Expand All @@ -58,6 +57,11 @@ func testAccDataSourceGoogleNetworkCheck(data_source_name string, resource_name
)
}
}

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}

return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func testAccDataSourceComputeResourcePolicyCheck(dataSourceName string, resource
rsAttr := rs.Primary.Attributes

policyAttrsToTest := []string{
"self_link",
"name",
}

Expand All @@ -65,6 +64,10 @@ func testAccDataSourceComputeResourcePolicyCheck(dataSourceName string, resource
}
}

if !compareSelfLinkOrResourceName("", dsAttr["self_link"], rsAttr["self_link"], nil) && dsAttr["self_link"] != rsAttr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", dsAttr["self_link"], rsAttr["self_link"])
}

return nil
}
}
Expand Down
9 changes: 6 additions & 3 deletions google-beta/data_source_google_compute_subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func testAccDataSourceGoogleSubnetworkCheck(data_source_name string, resource_na

subnetwork_attrs_to_test := []string{
"id",
"self_link",
"name",
"description",
"ip_cidr_range",
Expand All @@ -62,8 +61,12 @@ func testAccDataSourceGoogleSubnetworkCheck(data_source_name string, resource_na
}
}

if v1RsNetwork := ConvertSelfLinkToV1(rs_attr["network"]); ds_attr["network"] != v1RsNetwork {
return fmt.Errorf("network is %s; want %s", ds_attr["network"], v1RsNetwork)
if !compareSelfLinkOrResourceName("", ds_attr["network"], rs_attr["network"], nil) && ds_attr["network"] != rs_attr["network"] {
return fmt.Errorf("network does not match: %s vs %s", ds_attr["network"], rs_attr["network"])
}

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}

return nil
Expand Down
6 changes: 5 additions & 1 deletion google-beta/data_source_google_compute_vpn_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func testAccDataSourceGoogleVpnGatewayCheck(data_source_name string, resource_na
rs_attr := rs.Primary.Attributes
vpn_gateway_attrs_to_test := []string{
"id",
"self_link",
"name",
"description",
"network",
Expand All @@ -59,6 +58,11 @@ func testAccDataSourceGoogleVpnGatewayCheck(data_source_name string, resource_na
)
}
}

if !compareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}

return nil
}
}
Expand Down