From 5585b14069e215abab3ada2aba104dfbcebc61aa Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Wed, 13 Dec 2017 16:45:52 -0800 Subject: [PATCH] Import test refactoring for some resources. (#854) * Improve import tests for folder, org iam custom roles and org policies * improve import test for google project --- google/import_google_folder_test.go | 31 ------------- ...oogle_organization_iam_custom_role_test.go | 30 ------------- .../import_google_organization_policy_test.go | 27 ------------ google/import_google_project_test.go | 43 ------------------- google/resource_google_folder_test.go | 5 +++ ...oogle_organization_iam_custom_role_test.go | 5 +++ ...esource_google_organization_policy_test.go | 25 +++++++++++ google/resource_google_project_test.go | 10 +++++ 8 files changed, 45 insertions(+), 131 deletions(-) delete mode 100644 google/import_google_folder_test.go delete mode 100644 google/import_google_organization_iam_custom_role_test.go delete mode 100644 google/import_google_organization_policy_test.go delete mode 100644 google/import_google_project_test.go diff --git a/google/import_google_folder_test.go b/google/import_google_folder_test.go deleted file mode 100644 index 94399648..00000000 --- a/google/import_google_folder_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package google - -import ( - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" - "testing" -) - -func TestAccGoogleFolder_import(t *testing.T) { - t.Parallel() - - folderDisplayName := "tf-test-" + acctest.RandString(10) - org := getTestOrgFromEnv(t) - parent := "organizations/" + org - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckGoogleFolderDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccGoogleFolder_basic(folderDisplayName, parent), - }, - resource.TestStep{ - ResourceName: "google_folder.folder1", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} diff --git a/google/import_google_organization_iam_custom_role_test.go b/google/import_google_organization_iam_custom_role_test.go deleted file mode 100644 index 601d53d2..00000000 --- a/google/import_google_organization_iam_custom_role_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package google - -import ( - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" - "testing" -) - -func TestAccGoogleOrganizationIamCustomRole_import(t *testing.T) { - t.Parallel() - - org := getTestOrgFromEnv(t) - roleId := "tfIamRole" + acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckGoogleOrganizationIamCustomRoleDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckGoogleOrganizationIamCustomRole_update(org, roleId), - }, - { - ResourceName: "google_organization_iam_custom_role.foo", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} diff --git a/google/import_google_organization_policy_test.go b/google/import_google_organization_policy_test.go deleted file mode 100644 index 6ee95d6a..00000000 --- a/google/import_google_organization_policy_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package google - -import ( - "github.com/hashicorp/terraform/helper/resource" - "testing" -) - -func TestAccGoogleOrganizationPolicy_import(t *testing.T) { - t.Parallel() - - org := getTestOrgFromEnv(t) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccGoogleOrganizationPolicy_list_allowAll(org), - }, - { - ResourceName: "google_organization_policy.list", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} diff --git a/google/import_google_project_test.go b/google/import_google_project_test.go deleted file mode 100644 index 611eb483..00000000 --- a/google/import_google_project_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package google - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccGoogleProject_importBasic(t *testing.T) { - t.Parallel() - - org := getTestOrgFromEnv(t) - resourceName := "google_project.acceptance" - projectId := "terraform-" + acctest.RandString(10) - conf := testAccGoogleProject_import(projectId, org, pname) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: conf, - }, - - resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccGoogleProject_import(pid, orgId, projectName string) string { - return fmt.Sprintf(` -resource "google_project" "acceptance" { - project_id = "%s" - org_id = "%s" - name = "%s" -}`, pid, orgId, projectName) -} diff --git a/google/resource_google_folder_test.go b/google/resource_google_folder_test.go index 8a0fcc7f..8d372966 100644 --- a/google/resource_google_folder_test.go +++ b/google/resource_google_folder_test.go @@ -39,6 +39,11 @@ func TestAccGoogleFolder_rename(t *testing.T) { testAccCheckGoogleFolderParent(&folder, parent), testAccCheckGoogleFolderDisplayName(&folder, newFolderDisplayName), )}, + resource.TestStep{ + ResourceName: "google_folder.folder1", + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/google/resource_google_organization_iam_custom_role_test.go b/google/resource_google_organization_iam_custom_role_test.go index 378234e7..ac6fd6b6 100644 --- a/google/resource_google_organization_iam_custom_role_test.go +++ b/google/resource_google_organization_iam_custom_role_test.go @@ -39,6 +39,11 @@ func TestAccGoogleOrganizationIamCustomRole_basic(t *testing.T) { "BETA", []string{"resourcemanager.projects.list", "resourcemanager.organizations.get"}), }, + { + ResourceName: "google_organization_iam_custom_role.foo", + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/google/resource_google_organization_policy_test.go b/google/resource_google_organization_policy_test.go index 05fd65fd..cb7be710 100644 --- a/google/resource_google_organization_policy_test.go +++ b/google/resource_google_organization_policy_test.go @@ -47,6 +47,11 @@ func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) { Config: testAccGoogleOrganizationPolicy_boolean(org, true), Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", true), }, + { + ResourceName: "google_organization_policy.bool", + ImportState: true, + ImportStateVerify: true, + }, }, }) @@ -65,6 +70,11 @@ func TestAccGoogleOrganizationPolicy_list_allowAll(t *testing.T) { Config: testAccGoogleOrganizationPolicy_list_allowAll(org), Check: testAccCheckGoogleOrganizationListPolicyAll("list", "ALLOW"), }, + { + ResourceName: "google_organization_policy.list", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -83,6 +93,11 @@ func TestAccGoogleOrganizationPolicy_list_allowSome(t *testing.T) { Config: testAccGoogleOrganizationPolicy_list_allowSome(org, project), Check: testAccCheckGoogleOrganizationListPolicyAllowedValues("list", []string{project}), }, + { + ResourceName: "google_organization_policy.list", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -100,6 +115,11 @@ func TestAccGoogleOrganizationPolicy_list_denySome(t *testing.T) { Config: testAccGoogleOrganizationPolicy_list_denySome(org), Check: testAccCheckGoogleOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES), }, + { + ResourceName: "google_organization_policy.list", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -121,6 +141,11 @@ func TestAccGoogleOrganizationPolicy_list_update(t *testing.T) { Config: testAccGoogleOrganizationPolicy_list_denySome(org), Check: testAccCheckGoogleOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES), }, + { + ResourceName: "google_organization_policy.list", + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/google/resource_google_project_test.go b/google/resource_google_project_test.go index 6649fa80..502f28b8 100644 --- a/google/resource_google_project_test.go +++ b/google/resource_google_project_test.go @@ -86,6 +86,11 @@ func TestAccGoogleProject_createBilling(t *testing.T) { testAccCheckGoogleProjectHasBillingAccount("google_project.acceptance", pid, billingId), ), }, + resource.TestStep{ + ResourceName: "google_project.acceptance", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -106,6 +111,11 @@ func TestAccGoogleProject_createLabels(t *testing.T) { testAccCheckGoogleProjectHasLabels("google_project.acceptance", pid, map[string]string{"test": "that"}), ), }, + resource.TestStep{ + ResourceName: "google_project.acceptance", + ImportState: true, + ImportStateVerify: true, + }, }, }) }