Skip to content

Commit

Permalink
adding all remaining tests (#593)
Browse files Browse the repository at this point in the history
Merged PR #593.
  • Loading branch information
chrisst authored and modular-magician committed Oct 22, 2018
1 parent 51f2020 commit c3fd5f9
Show file tree
Hide file tree
Showing 73 changed files with 19,546 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/terraform
78 changes: 78 additions & 0 deletions provider/terraform/tests/data_source_container_registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package google

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestDataSourceGoogleContainerRegistryRepository(t *testing.T) {
t.Parallel()

resourceName := "data.google_container_registry_repository.default"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleContainerRegistryRepo_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project"),
resource.TestCheckResourceAttrSet(resourceName, "region"),
resource.TestCheckResourceAttr(resourceName, "repository_url", "bar.gcr.io/foo"),
),
},
},
})
}

const testAccCheckGoogleContainerRegistryRepo_basic = `
data "google_container_registry_repository" "default" {
project = "foo"
region = "bar"
}
`

func TestDataSourceGoogleContainerRegistryImage(t *testing.T) {
t.Parallel()

resourceName := "data.google_container_registry_image.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleContainerRegistryImage_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project"),
resource.TestCheckResourceAttrSet(resourceName, "region"),
resource.TestCheckResourceAttr(resourceName, "image_url", "bar.gcr.io/foo/baz"),
resource.TestCheckResourceAttr(resourceName+"2", "image_url", "bar.gcr.io/foo/baz:qux"),
resource.TestCheckResourceAttr(resourceName+"3", "image_url", "bar.gcr.io/foo/baz@1234"),
),
},
},
})
}

const testAccCheckGoogleContainerRegistryImage_basic = `
data "google_container_registry_image" "test" {
project = "foo"
region = "bar"
name = "baz"
}
data "google_container_registry_image" "test2" {
project = "foo"
region = "bar"
name = "baz"
tag = "qux"
}
data "google_container_registry_image" "test3" {
project = "foo"
region = "bar"
name = "baz"
digest = "1234"
}
`
73 changes: 73 additions & 0 deletions provider/terraform/tests/data_source_dns_managed_zone_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccDataSourceDnsManagedZone_basic(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsManagedZoneDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataSourceDnsManagedZone_basic(),
Check: testAccDataSourceDnsManagedZoneCheck("data.google_dns_managed_zone.qa", "google_dns_managed_zone.foo"),
},
},
})
}

func testAccDataSourceDnsManagedZoneCheck(dsName, rsName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ds, ok := s.RootModule().Resources[rsName]
if !ok {
return fmt.Errorf("can't find resource called %s in state", rsName)
}

rs, ok := s.RootModule().Resources[dsName]
if !ok {
return fmt.Errorf("can't find data source called %s in state", dsName)
}

dsAttr := ds.Primary.Attributes
rsAttr := rs.Primary.Attributes

attrsToTest := []string{
"id",
"name",
"description",
"dns_name",
"name_servers",
}

for _, attrToTest := range attrsToTest {
if dsAttr[attrToTest] != rsAttr[attrToTest] {
return fmt.Errorf("%s is %s; want %s", attrToTest, dsAttr[attrToTest], rsAttr[attrToTest])
}
}

return nil
}
}

func testAccDataSourceDnsManagedZone_basic() string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "foo" {
name = "qa-zone-%s"
dns_name = "qa.tf-test.club."
description = "QA DNS zone"
}
data "google_dns_managed_zone" "qa" {
name = "${google_dns_managed_zone.foo.name}"
}
`, acctest.RandString(10))
}
94 changes: 94 additions & 0 deletions provider/terraform/tests/data_source_google_active_folder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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)
}
104 changes: 104 additions & 0 deletions provider/terraform/tests/data_source_google_billing_account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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)
}
32 changes: 32 additions & 0 deletions provider/terraform/tests/data_source_google_client_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package google

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceGoogleClientConfig_basic(t *testing.T) {
t.Parallel()

resourceName := "data.google_client_config.current"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleClientConfig_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project"),
resource.TestCheckResourceAttrSet(resourceName, "region"),
resource.TestCheckResourceAttrSet(resourceName, "access_token"),
),
},
},
})
}

const testAccCheckGoogleClientConfig_basic = `
data "google_client_config" "current" { }
`
Loading

0 comments on commit c3fd5f9

Please sign in to comment.