Skip to content

Commit e48f247

Browse files
authored
org policy test fixes (#1059)
1 parent 5db0c53 commit e48f247

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

google/resource_google_folder_organization_policy_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package google
33
import (
44
"fmt"
55
"reflect"
6+
"sort"
67
"testing"
78

89
"github.com/hashicorp/terraform/helper/acctest"
@@ -194,6 +195,8 @@ func testAccCheckGoogleFolderOrganizationListPolicyAllowedValues(n string, value
194195
return err
195196
}
196197

198+
sort.Strings(policy.ListPolicy.AllowedValues)
199+
sort.Strings(values)
197200
if !reflect.DeepEqual(policy.ListPolicy.AllowedValues, values) {
198201
return fmt.Errorf("Expected the list policy to allow '%s', instead allowed '%s'", values, policy.ListPolicy.AllowedValues)
199202
}
@@ -209,6 +212,8 @@ func testAccCheckGoogleFolderOrganizationListPolicyDeniedValues(n string, values
209212
return err
210213
}
211214

215+
sort.Strings(policy.ListPolicy.DeniedValues)
216+
sort.Strings(values)
212217
if !reflect.DeepEqual(policy.ListPolicy.DeniedValues, values) {
213218
return fmt.Errorf("Expected the list policy to deny '%s', instead denied '%s'", values, policy.ListPolicy.DeniedValues)
214219
}
@@ -303,14 +308,14 @@ resource "google_folder" "orgpolicy" {
303308
}
304309
305310
resource "google_folder_organization_policy" "list" {
306-
folder = "${google_folder.orgpolicy.name}"
311+
folder = "${google_folder.orgpolicy.name}"
307312
constraint = "serviceuser.services"
308313
309314
list_policy {
310315
deny {
311316
values = [
312-
"maps-ios-backend.googleapis.com",
313-
"placesios.googleapis.com",
317+
"doubleclicksearch.googleapis.com",
318+
"replicapoolupdater.googleapis.com",
314319
]
315320
}
316321
}

google/resource_google_organization_policy_test.go

+16-17
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ package google
22

33
import (
44
"fmt"
5+
"reflect"
6+
"sort"
7+
"testing"
8+
59
"github.com/hashicorp/terraform/helper/resource"
610
"github.com/hashicorp/terraform/terraform"
711
"google.golang.org/api/cloudresourcemanager/v1"
8-
"reflect"
9-
"testing"
1012
)
1113

1214
var DENIED_ORG_POLICIES = []string{
13-
"maps-ios-backend.googleapis.com",
14-
"placesios.googleapis.com",
15+
"doubleclicksearch.googleapis.com",
16+
"replicapoolupdater.googleapis.com",
1517
}
1618

17-
func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) {
18-
t.Parallel()
19+
// Since each test here is acting on the same organization, run the tests serially to
20+
// avoid race conditions and aborted operations.
1921

22+
func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) {
2023
org := getTestOrgFromEnv(t)
2124
resource.Test(t, resource.TestCase{
2225
PreCheck: func() { testAccPreCheck(t) },
@@ -58,8 +61,6 @@ func TestAccGoogleOrganizationPolicy_boolean(t *testing.T) {
5861
}
5962

6063
func TestAccGoogleOrganizationPolicy_list_allowAll(t *testing.T) {
61-
t.Parallel()
62-
6364
org := getTestOrgFromEnv(t)
6465
resource.Test(t, resource.TestCase{
6566
PreCheck: func() { testAccPreCheck(t) },
@@ -80,8 +81,6 @@ func TestAccGoogleOrganizationPolicy_list_allowAll(t *testing.T) {
8081
}
8182

8283
func TestAccGoogleOrganizationPolicy_list_allowSome(t *testing.T) {
83-
t.Parallel()
84-
8584
org := getTestOrgFromEnv(t)
8685
project := getTestProjectFromEnv()
8786
resource.Test(t, resource.TestCase{
@@ -103,8 +102,6 @@ func TestAccGoogleOrganizationPolicy_list_allowSome(t *testing.T) {
103102
}
104103

105104
func TestAccGoogleOrganizationPolicy_list_denySome(t *testing.T) {
106-
t.Parallel()
107-
108105
org := getTestOrgFromEnv(t)
109106
resource.Test(t, resource.TestCase{
110107
PreCheck: func() { testAccPreCheck(t) },
@@ -125,8 +122,6 @@ func TestAccGoogleOrganizationPolicy_list_denySome(t *testing.T) {
125122
}
126123

127124
func TestAccGoogleOrganizationPolicy_list_update(t *testing.T) {
128-
t.Parallel()
129-
130125
org := getTestOrgFromEnv(t)
131126
resource.Test(t, resource.TestCase{
132127
PreCheck: func() { testAccPreCheck(t) },
@@ -216,6 +211,8 @@ func testAccCheckGoogleOrganizationListPolicyAllowedValues(n string, values []st
216211
return err
217212
}
218213

214+
sort.Strings(policy.ListPolicy.AllowedValues)
215+
sort.Strings(values)
219216
if !reflect.DeepEqual(policy.ListPolicy.AllowedValues, values) {
220217
return fmt.Errorf("Expected the list policy to allow '%s', instead allowed '%s'", values, policy.ListPolicy.AllowedValues)
221218
}
@@ -231,6 +228,8 @@ func testAccCheckGoogleOrganizationListPolicyDeniedValues(n string, values []str
231228
return err
232229
}
233230

231+
sort.Strings(policy.ListPolicy.DeniedValues)
232+
sort.Strings(values)
234233
if !reflect.DeepEqual(policy.ListPolicy.DeniedValues, values) {
235234
return fmt.Errorf("Expected the list policy to deny '%s', instead denied '%s'", values, policy.ListPolicy.DeniedValues)
236235
}
@@ -306,13 +305,13 @@ func testAccGoogleOrganizationPolicy_list_denySome(org string) string {
306305
return fmt.Sprintf(`
307306
resource "google_organization_policy" "list" {
308307
org_id = "%s"
309-
constraint = "serviceuser.services"
308+
constraint = "serviceuser.services"
310309
311310
list_policy {
312311
deny {
313312
values = [
314-
"maps-ios-backend.googleapis.com",
315-
"placesios.googleapis.com",
313+
"doubleclicksearch.googleapis.com",
314+
"replicapoolupdater.googleapis.com",
316315
]
317316
}
318317
}

0 commit comments

Comments
 (0)