From 625c4576d480006c53d0ac9ffe631465801904db Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Tue, 5 Nov 2019 20:43:28 +0000 Subject: [PATCH] Add safe `self_link` comparison to compute DS tests Signed-off-by: Modular Magician --- google-beta/data_source_google_compute_address_test.go | 5 ++++- .../data_source_google_compute_forwarding_rule_test.go | 6 +++++- .../data_source_google_compute_global_address_test.go | 5 ++++- google-beta/data_source_google_compute_image_test.go | 9 +++++++-- .../data_source_google_compute_instance_group_test.go | 5 ++++- google-beta/data_source_google_compute_network_test.go | 6 +++++- .../data_source_google_compute_resource_policy_test.go | 5 ++++- .../data_source_google_compute_subnetwork_test.go | 9 ++++++--- .../data_source_google_compute_vpn_gateway_test.go | 6 +++++- 9 files changed, 44 insertions(+), 12 deletions(-) diff --git a/google-beta/data_source_google_compute_address_test.go b/google-beta/data_source_google_compute_address_test.go index 5dc8157b53..b8631cf259 100644 --- a/google-beta/data_source_google_compute_address_test.go +++ b/google-beta/data_source_google_compute_address_test.go @@ -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", } @@ -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"]) } diff --git a/google-beta/data_source_google_compute_forwarding_rule_test.go b/google-beta/data_source_google_compute_forwarding_rule_test.go index 5706c46d91..88b6114351 100644 --- a/google-beta/data_source_google_compute_forwarding_rule_test.go +++ b/google-beta/data_source_google_compute_forwarding_rule_test.go @@ -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", @@ -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 } } diff --git a/google-beta/data_source_google_compute_global_address_test.go b/google-beta/data_source_google_compute_global_address_test.go index 2b375c831c..3e93935d27 100644 --- a/google-beta/data_source_google_compute_global_address_test.go +++ b/google-beta/data_source_google_compute_global_address_test.go @@ -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", } @@ -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"]) } diff --git a/google-beta/data_source_google_compute_image_test.go b/google-beta/data_source_google_compute_image_test.go index e94ce8e281..acb00158fd 100644 --- a/google-beta/data_source_google_compute_image_test.go +++ b/google-beta/data_source_google_compute_image_test.go @@ -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 { @@ -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 } } diff --git a/google-beta/data_source_google_compute_instance_group_test.go b/google-beta/data_source_google_compute_instance_group_test.go index 0261d11c4d..1e35c34167 100644 --- a/google-beta/data_source_google_compute_instance_group_test.go +++ b/google-beta/data_source_google_compute_instance_group_test.go @@ -89,7 +89,6 @@ func testAccCheckDataSourceGoogleComputeInstanceGroup(dataSourceName string) res "project", "description", "network", - "self_link", "size", } @@ -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") diff --git a/google-beta/data_source_google_compute_network_test.go b/google-beta/data_source_google_compute_network_test.go index c8ad27dda0..16cec24c47 100644 --- a/google-beta/data_source_google_compute_network_test.go +++ b/google-beta/data_source_google_compute_network_test.go @@ -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", } @@ -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 } } diff --git a/google-beta/data_source_google_compute_resource_policy_test.go b/google-beta/data_source_google_compute_resource_policy_test.go index 33e844ea2b..5209118fca 100644 --- a/google-beta/data_source_google_compute_resource_policy_test.go +++ b/google-beta/data_source_google_compute_resource_policy_test.go @@ -50,7 +50,6 @@ func testAccDataSourceComputeResourcePolicyCheck(dataSourceName string, resource rsAttr := rs.Primary.Attributes policyAttrsToTest := []string{ - "self_link", "name", } @@ -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 } } diff --git a/google-beta/data_source_google_compute_subnetwork_test.go b/google-beta/data_source_google_compute_subnetwork_test.go index 13fd9eafac..36a34f90c0 100644 --- a/google-beta/data_source_google_compute_subnetwork_test.go +++ b/google-beta/data_source_google_compute_subnetwork_test.go @@ -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", @@ -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 diff --git a/google-beta/data_source_google_compute_vpn_gateway_test.go b/google-beta/data_source_google_compute_vpn_gateway_test.go index 041f78d71f..09542f19ce 100644 --- a/google-beta/data_source_google_compute_vpn_gateway_test.go +++ b/google-beta/data_source_google_compute_vpn_gateway_test.go @@ -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", @@ -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 } }