mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-08-31 06:10:20 +00:00
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
![]() |
package google
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"regexp"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||
|
"github.com/hashicorp/terraform/helper/resource"
|
||
|
)
|
||
|
|
||
|
func TestAccDataSourceGoogleOrganization_byFullName(t *testing.T) {
|
||
|
orgId := getTestOrgFromEnv(t)
|
||
|
name := "organizations/" + orgId
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccCheckGoogleOrganization_byName(name),
|
||
|
Check: resource.ComposeTestCheckFunc(
|
||
|
resource.TestCheckResourceAttr("data.google_organization.org", "id", orgId),
|
||
|
resource.TestCheckResourceAttr("data.google_organization.org", "name", name),
|
||
|
),
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func TestAccDataSourceGoogleOrganization_byShortName(t *testing.T) {
|
||
|
orgId := getTestOrgFromEnv(t)
|
||
|
name := "organizations/" + orgId
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccCheckGoogleOrganization_byName(orgId),
|
||
|
Check: resource.ComposeTestCheckFunc(
|
||
|
resource.TestCheckResourceAttr("data.google_organization.org", "id", orgId),
|
||
|
resource.TestCheckResourceAttr("data.google_organization.org", "name", name),
|
||
|
),
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func TestAccDataSourceGoogleOrganization_byDomain(t *testing.T) {
|
||
|
name := acctest.RandString(16) + ".com"
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccCheckGoogleOrganization_byDomain(name),
|
||
|
ExpectError: regexp.MustCompile("Organization not found: " + name),
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func testAccCheckGoogleOrganization_byName(name string) string {
|
||
|
return fmt.Sprintf(`
|
||
|
data "google_organization" "org" {
|
||
|
organization = "%s"
|
||
|
}`, name)
|
||
|
}
|
||
|
|
||
|
func testAccCheckGoogleOrganization_byDomain(name string) string {
|
||
|
return fmt.Sprintf(`
|
||
|
data "google_organization" "org" {
|
||
|
domain = "%s"
|
||
|
}`, name)
|
||
|
}
|