org policy test fixes (#1059)

This commit is contained in:
Dana Hoffman 2018-02-07 14:55:03 -08:00 committed by GitHub
parent 5db0c53f32
commit e48f247196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 20 deletions

View File

@ -3,6 +3,7 @@ package google
import (
"fmt"
"reflect"
"sort"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
@ -194,6 +195,8 @@ func testAccCheckGoogleFolderOrganizationListPolicyAllowedValues(n string, value
return err
}
sort.Strings(policy.ListPolicy.AllowedValues)
sort.Strings(values)
if !reflect.DeepEqual(policy.ListPolicy.AllowedValues, values) {
return fmt.Errorf("Expected the list policy to allow '%s', instead allowed '%s'", values, policy.ListPolicy.AllowedValues)
}
@ -209,6 +212,8 @@ func testAccCheckGoogleFolderOrganizationListPolicyDeniedValues(n string, values
return err
}
sort.Strings(policy.ListPolicy.DeniedValues)
sort.Strings(values)
if !reflect.DeepEqual(policy.ListPolicy.DeniedValues, values) {
return fmt.Errorf("Expected the list policy to deny '%s', instead denied '%s'", values, policy.ListPolicy.DeniedValues)
}
@ -303,14 +308,14 @@ resource "google_folder" "orgpolicy" {
}
resource "google_folder_organization_policy" "list" {
folder = "${google_folder.orgpolicy.name}"
folder = "${google_folder.orgpolicy.name}"
constraint = "serviceuser.services"
list_policy {
deny {
values = [
"maps-ios-backend.googleapis.com",
"placesios.googleapis.com",
"doubleclicksearch.googleapis.com",
"replicapoolupdater.googleapis.com",
]
}
}

View File

@ -2,21 +2,24 @@ package google
import (
"fmt"
"reflect"
"sort"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"google.golang.org/api/cloudresourcemanager/v1"
"reflect"
"testing"
)
var DENIED_ORG_POLICIES = []string{
"maps-ios-backend.googleapis.com",
"placesios.googleapis.com",
"doubleclicksearch.googleapis.com",
"replicapoolupdater.googleapis.com",
}
func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) {
t.Parallel()
// Since each test here is acting on the same organization, run the tests serially to
// avoid race conditions and aborted operations.
func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) {
org := getTestOrgFromEnv(t)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -58,8 +61,6 @@ func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) {
}
func TestAccGoogleOrganizationPolicy_list_allowAll(t *testing.T) {
t.Parallel()
org := getTestOrgFromEnv(t)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -80,8 +81,6 @@ func TestAccGoogleOrganizationPolicy_list_allowAll(t *testing.T) {
}
func TestAccGoogleOrganizationPolicy_list_allowSome(t *testing.T) {
t.Parallel()
org := getTestOrgFromEnv(t)
project := getTestProjectFromEnv()
resource.Test(t, resource.TestCase{
@ -103,8 +102,6 @@ func TestAccGoogleOrganizationPolicy_list_allowSome(t *testing.T) {
}
func TestAccGoogleOrganizationPolicy_list_denySome(t *testing.T) {
t.Parallel()
org := getTestOrgFromEnv(t)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -125,8 +122,6 @@ func TestAccGoogleOrganizationPolicy_list_denySome(t *testing.T) {
}
func TestAccGoogleOrganizationPolicy_list_update(t *testing.T) {
t.Parallel()
org := getTestOrgFromEnv(t)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -216,6 +211,8 @@ func testAccCheckGoogleOrganizationListPolicyAllowedValues(n string, values []st
return err
}
sort.Strings(policy.ListPolicy.AllowedValues)
sort.Strings(values)
if !reflect.DeepEqual(policy.ListPolicy.AllowedValues, values) {
return fmt.Errorf("Expected the list policy to allow '%s', instead allowed '%s'", values, policy.ListPolicy.AllowedValues)
}
@ -231,6 +228,8 @@ func testAccCheckGoogleOrganizationListPolicyDeniedValues(n string, values []str
return err
}
sort.Strings(policy.ListPolicy.DeniedValues)
sort.Strings(values)
if !reflect.DeepEqual(policy.ListPolicy.DeniedValues, values) {
return fmt.Errorf("Expected the list policy to deny '%s', instead denied '%s'", values, policy.ListPolicy.DeniedValues)
}
@ -306,13 +305,13 @@ func testAccGoogleOrganizationPolicy_list_denySome(org string) string {
return fmt.Sprintf(`
resource "google_organization_policy" "list" {
org_id = "%s"
constraint = "serviceuser.services"
constraint = "serviceuser.services"
list_policy {
deny {
values = [
"maps-ios-backend.googleapis.com",
"placesios.googleapis.com",
"doubleclicksearch.googleapis.com",
"replicapoolupdater.googleapis.com",
]
}
}