terraform-provider-google/google/data_source_google_organization_test.go
Kit Ewbank 49a0008643 Add 'google_organization' data source (#887)
* Add 'google_organization' data source.

* Use 'GetResourceNameFromSelfLink'.

* Remove 'resourcemanager_helpers'.

* Use 'ConflictsWith' in schema.

* Add 'organization' argument and make 'name' an output-only attribute.
2017-12-21 16:12:44 -08:00

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)
}