github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_canonical_user_id_test.go (about)

     1  // make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccDataSourceAwsCanonicalUserId_'
     2  
     3  package aws
     4  
     5  import (
     6  	"fmt"
     7  	"testing"
     8  
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccDataSourceAwsCanonicalUserId_basic(t *testing.T) {
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:  func() { testAccPreCheck(t) },
    16  		Providers: testAccProviders,
    17  		Steps: []resource.TestStep{
    18  			{
    19  				Config: testAccDataSourceAwsCanonicalUserIdConfig,
    20  				Check: resource.ComposeTestCheckFunc(
    21  					testAccDataSourceAwsCanonicalUserIdCheckExists("data.aws_canonical_user_id.current"),
    22  				),
    23  			},
    24  		},
    25  	})
    26  }
    27  
    28  func testAccDataSourceAwsCanonicalUserIdCheckExists(name string) resource.TestCheckFunc {
    29  	return func(s *terraform.State) error {
    30  		rs, ok := s.RootModule().Resources[name]
    31  		if !ok {
    32  			return fmt.Errorf("Can't find Canonical User ID resource: %s", name)
    33  		}
    34  
    35  		if rs.Primary.Attributes["id"] == "" {
    36  			return fmt.Errorf("Missing Canonical User ID")
    37  		}
    38  		if rs.Primary.Attributes["display_name"] == "" {
    39  			return fmt.Errorf("Missing Display Name")
    40  		}
    41  
    42  		return nil
    43  	}
    44  }
    45  
    46  const testAccDataSourceAwsCanonicalUserIdConfig = `
    47  provider "aws" {
    48    region = "us-west-2"
    49  }
    50  
    51  data "aws_canonical_user_id" "current" { }
    52  `