mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-05 02:01:05 +00:00
a086e70e79
* Add 'google_billing_account' data source. * Use 'GetResourceNameFromSelfLink'. * Use 'ConflictsWith' in schema. * Use pagination for List() API call. * Add ability to filter by 'open' attribute. * Don't use 'ForceNew' for data sources. * Add 'billing_account' argument and make 'name' an output-only attribute. * Correct error message.
105 lines
2.9 KiB
Go
105 lines
2.9 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestAccDataSourceGoogleBillingAccount_byFullName(t *testing.T) {
|
|
billingId := getTestBillingAccountFromEnv(t)
|
|
name := "billingAccounts/" + billingId
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleBillingAccount_byName(name),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("data.google_billing_account.acct", "id", billingId),
|
|
resource.TestCheckResourceAttr("data.google_billing_account.acct", "name", name),
|
|
resource.TestCheckResourceAttr("data.google_billing_account.acct", "open", "true"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccDataSourceGoogleBillingAccount_byShortName(t *testing.T) {
|
|
billingId := getTestBillingAccountFromEnv(t)
|
|
name := "billingAccounts/" + billingId
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleBillingAccount_byName(billingId),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("data.google_billing_account.acct", "id", billingId),
|
|
resource.TestCheckResourceAttr("data.google_billing_account.acct", "name", name),
|
|
resource.TestCheckResourceAttr("data.google_billing_account.acct", "open", "true"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccDataSourceGoogleBillingAccount_byFullNameClosed(t *testing.T) {
|
|
billingId := getTestBillingAccountFromEnv(t)
|
|
name := "billingAccounts/" + billingId
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleBillingAccount_byNameClosed(name),
|
|
ExpectError: regexp.MustCompile("Billing account not found: " + name),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccDataSourceGoogleBillingAccount_byDisplayName(t *testing.T) {
|
|
name := acctest.RandString(16)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleBillingAccount_byDisplayName(name),
|
|
ExpectError: regexp.MustCompile("Billing account not found: " + name),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckGoogleBillingAccount_byName(name string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_billing_account" "acct" {
|
|
billing_account = "%s"
|
|
}`, name)
|
|
}
|
|
|
|
func testAccCheckGoogleBillingAccount_byNameClosed(name string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_billing_account" "acct" {
|
|
billing_account = "%s"
|
|
open = false
|
|
}`, name)
|
|
}
|
|
|
|
func testAccCheckGoogleBillingAccount_byDisplayName(name string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_billing_account" "acct" {
|
|
display_name = "%s"
|
|
}`, name)
|
|
}
|