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

     1  package pagerduty
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/resource"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  func TestAccDataSourcePagerDutyVendor_Basic(t *testing.T) {
    12  	resource.Test(t, resource.TestCase{
    13  		PreCheck:     func() { testAccPreCheck(t) },
    14  		Providers:    testAccProviders,
    15  		CheckDestroy: testAccCheckPagerDutyScheduleDestroy,
    16  		Steps: []resource.TestStep{
    17  			{
    18  				Config: testAccDataSourcePagerDutyVendorConfig,
    19  				Check: resource.ComposeTestCheckFunc(
    20  					testAccDataSourcePagerDutyVendor("data.pagerduty_vendor.foo"),
    21  				),
    22  			},
    23  		},
    24  	})
    25  }
    26  
    27  func testAccDataSourcePagerDutyVendor(n string) resource.TestCheckFunc {
    28  	return func(s *terraform.State) error {
    29  
    30  		r := s.RootModule().Resources[n]
    31  		a := r.Primary.Attributes
    32  
    33  		if a["id"] == "" {
    34  			return fmt.Errorf("Expected to get a vendor ID from PagerDuty")
    35  		}
    36  
    37  		if a["id"] != "PZQ6AUS" {
    38  			return fmt.Errorf("Expected the Datadog Vendor ID to be: PZQ6AUS, but got: %s", a["id"])
    39  		}
    40  
    41  		if a["name"] != "Amazon Cloudwatch" {
    42  			return fmt.Errorf("Expected the Datadog Vendor Name to be: Datadog, but got: %s", a["name"])
    43  		}
    44  
    45  		if a["type"] != "api" {
    46  			return fmt.Errorf("Expected the Datadog Vendor Type to be: api, but got: %s", a["type"])
    47  		}
    48  
    49  		return nil
    50  	}
    51  }
    52  
    53  const testAccDataSourcePagerDutyVendorConfig = `
    54  data "pagerduty_vendor" "foo" {
    55    name = "cloudwatch"
    56  }
    57  `