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
This commit is contained in:
Vincent Roseberry 2017-12-13 16:45:52 -08:00 committed by GitHub
parent e4516341ad
commit 5585b14069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 131 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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