Skip to content

Commit

Permalink
Add safe self_link comparison to compute DS tests (#2586)
Browse files Browse the repository at this point in the history
Merged PR #2586.
  • Loading branch information
rileykarson authored and modular-magician committed Nov 5, 2019
1 parent e655cea commit 163f190
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
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
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 @@ -90,7 +90,6 @@ func testAccCheckDataSourceGoogleComputeInstanceGroup(dataSourceName string) res
"project",
"description",
"network",
"self_link",
"size",
}

Expand All @@ -100,6 +99,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
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 @@ -52,7 +52,6 @@ func testAccDataSourceComputeResourcePolicyCheck(dataSourceName string, resource
rsAttr := rs.Primary.Attributes

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

Expand All @@ -67,6 +66,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
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
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

0 comments on commit 163f190

Please sign in to comment.