-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
third_party/terraform/tests/data_source_google_folder_organization_policy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDataSourceGoogleFolderOrganizationPolicy_basic(t *testing.T) { | ||
folder := acctest.RandomWithPrefix("tf-test") | ||
org := getTestOrgFromEnv(t) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleFolderOrganizationPolicy_basic(org, folder), | ||
Check: testAccDataSourceGoogleOrganizationPolicyCheck( | ||
"data.google_folder_organization_policy.data", | ||
"google_folder_organization_policy.resource"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleOrganizationPolicyCheck(dataSourceName string, resourceName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
ds, ok := s.RootModule().Resources[dataSourceName] | ||
if !ok { | ||
return fmt.Errorf("root module has no resource called %s", dataSourceName) | ||
} | ||
|
||
rs, ok := s.RootModule().Resources[resourceName] | ||
if !ok { | ||
return fmt.Errorf("can't find %s in state", resourceName) | ||
} | ||
|
||
dsAttr := ds.Primary.Attributes | ||
rsAttr := rs.Primary.Attributes | ||
|
||
cloudFuncAttrToCheck := []string{ | ||
"name", | ||
"folder", | ||
"constraint", | ||
"version", | ||
"list_policy", | ||
"restore_policy", | ||
"boolean_policy", | ||
} | ||
|
||
for _, attr := range cloudFuncAttrToCheck { | ||
if dsAttr[attr] != rsAttr[attr] { | ||
return fmt.Errorf( | ||
"%s is %s; want %s", | ||
attr, | ||
dsAttr[attr], | ||
rsAttr[attr], | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccDataSourceGoogleFolderOrganizationPolicy_basic(org, folder string) string { | ||
return fmt.Sprintf(` | ||
resource "google_folder" "orgpolicy" { | ||
display_name = "%s" | ||
parent = "%s" | ||
} | ||
resource "google_folder_organization_policy" "resource" { | ||
folder = "${google_folder.orgpolicy.name}" | ||
constraint = "serviceuser.services" | ||
restore_policy { | ||
default = true | ||
} | ||
} | ||
data "google_folder_organization_policy" "data" { | ||
folder = "${google_folder.orgpolicy.name}" | ||
constraint = "serviceuser.services" | ||
} | ||
`, folder, "organizations/"+org) | ||
} |
47 changes: 47 additions & 0 deletions
47
third_party/terraform/tests/data_source_google_project_organization_policy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGoogleProjectOrganizationPolicy_basic(t *testing.T) { | ||
project := getTestProjectFromEnv() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleProjectOrganizationPolicy_basic(project), | ||
Check: testAccDataSourceGoogleOrganizationPolicyCheck( | ||
"data.google_project_organization_policy.data", | ||
"google_project_organization_policy.resource"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleProjectOrganizationPolicy_basic(project string) string { | ||
return fmt.Sprintf(` | ||
resource "google_project_organization_policy" "resource" { | ||
project = "%s" | ||
constraint = "constraints/compute.trustedImageProjects" | ||
list_policy { | ||
allow { | ||
all = true | ||
} | ||
} | ||
} | ||
data "google_project_organization_policy" "data" { | ||
project = "%s" | ||
constraint = "constraints/compute.trustedImageProjects" | ||
} | ||
`, project, project) | ||
} |