mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Thom Knowles](/assets/img/avatar_default.png)
* escape the folder name (in case of spaces, etc) * add test case for folder with space * add missing args * make separate tests for each folder test, get folder name length under API limits * further abstract out the resource name to prevent test collisions * workaround multiple results returning for a given query by looping over return * split test cases into separate funcs
95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccDataSourceGoogleActiveFolder_default(t *testing.T) {
|
|
org := getTestOrgFromEnv(t)
|
|
|
|
parent := fmt.Sprintf("organizations/%s", org)
|
|
displayName := "terraform-test-" + acctest.RandString(10)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccDataSourceGoogleActiveFolderConfig(parent, displayName),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccDataSourceGoogleActiveFolderCheck("data.google_active_folder.my_folder", "google_folder.foobar"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccDataSourceGoogleActiveFolder_space(t *testing.T) {
|
|
org := getTestOrgFromEnv(t)
|
|
|
|
parent := fmt.Sprintf("organizations/%s", org)
|
|
displayName := "terraform test " + acctest.RandString(10)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccDataSourceGoogleActiveFolderConfig(parent, displayName),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccDataSourceGoogleActiveFolderCheck("data.google_active_folder.my_folder", "google_folder.foobar"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccDataSourceGoogleActiveFolderCheck(data_source_name string, resource_name string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
ds, ok := s.RootModule().Resources[data_source_name]
|
|
if !ok {
|
|
return fmt.Errorf("root module has no resource called %s", data_source_name)
|
|
}
|
|
|
|
rs, ok := s.RootModule().Resources[resource_name]
|
|
if !ok {
|
|
return fmt.Errorf("can't find %s in state", resource_name)
|
|
}
|
|
|
|
ds_attr := ds.Primary.Attributes
|
|
rs_attr := rs.Primary.Attributes
|
|
folder_attrs_to_test := []string{"parent", "display_name", "name"}
|
|
|
|
for _, attr_to_check := range folder_attrs_to_test {
|
|
if ds_attr[attr_to_check] != rs_attr[attr_to_check] {
|
|
return fmt.Errorf(
|
|
"%s is %s; want %s",
|
|
attr_to_check,
|
|
ds_attr[attr_to_check],
|
|
rs_attr[attr_to_check],
|
|
)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccDataSourceGoogleActiveFolderConfig(parent string, displayName string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_folder" "foobar" {
|
|
parent = "%s"
|
|
display_name = "%s"
|
|
}
|
|
|
|
data "google_active_folder" "my_folder" {
|
|
parent = "${google_folder.foobar.parent}"
|
|
display_name = "${google_folder.foobar.display_name}"
|
|
}
|
|
`, parent, displayName)
|
|
}
|