terraform-provider-google/google/data_source_google_service_account_test.go
Dana Hoffman cc98692acd
move all remaining import_ tests into resource-specific tests (#2060)
I also did a bit of cleanup while I was here and noticed things that I thought could be improved in the files (wording changes, removing tests that aren't quite necessary, etc.) Take a look and make sure I didn't actually remove anything important!
2018-09-17 11:15:11 -07:00

48 lines
1.4 KiB
Go

package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccDatasourceGoogleServiceAccount_basic(t *testing.T) {
t.Parallel()
resourceName := "data.google_service_account.acceptance"
account := acctest.RandomWithPrefix("tf-test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleServiceAccount_basic(account),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
resourceName, "id", fmt.Sprintf("projects/%s/serviceAccounts/%s@%s.iam.gserviceaccount.com", getTestProjectFromEnv(), account, getTestProjectFromEnv())),
resource.TestCheckResourceAttrSet(resourceName, "email"),
resource.TestCheckResourceAttrSet(resourceName, "unique_id"),
resource.TestCheckResourceAttrSet(resourceName, "name"),
resource.TestCheckResourceAttrSet(resourceName, "display_name"),
),
},
},
})
}
func testAccCheckGoogleServiceAccount_basic(account string) string {
return fmt.Sprintf(`
resource "google_service_account" "acceptance" {
account_id = "%s"
display_name = "Testing Account"
}
data "google_service_account" "acceptance" {
account_id = "${google_service_account.acceptance.account_id}"
}
`, account)
}