github.com/peterbale/terraform@v0.9.0-beta2.0.20170315142748-5723acd55547/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  			resource.TestStep{
    18  				Config: testAccDataSourcePagerDutyVendorConfig,
    19  				Check: resource.ComposeTestCheckFunc(
    20  					testAccDataSourcePagerDutyVendor("data.pagerduty_vendor.foo"),
    21  				),
    22  			},
    23  		},
    24  	})
    25  }
    26  
    27  func TestAccDataSourcePagerDutyVendorLegacy_Basic(t *testing.T) {
    28  	resource.Test(t, resource.TestCase{
    29  		PreCheck:     func() { testAccPreCheck(t) },
    30  		Providers:    testAccProviders,
    31  		CheckDestroy: testAccCheckPagerDutyScheduleDestroy,
    32  		Steps: []resource.TestStep{
    33  			resource.TestStep{
    34  				Config: testAccDataSourcePagerDutyVendorLegacyConfig,
    35  				Check: resource.ComposeTestCheckFunc(
    36  					testAccDataSourcePagerDutyVendorLegacy("data.pagerduty_vendor.foo"),
    37  				),
    38  			},
    39  		},
    40  	})
    41  }
    42  
    43  func testAccDataSourcePagerDutyVendor(n string) resource.TestCheckFunc {
    44  	return func(s *terraform.State) error {
    45  
    46  		r := s.RootModule().Resources[n]
    47  		a := r.Primary.Attributes
    48  
    49  		if a["id"] == "" {
    50  			return fmt.Errorf("Expected to get a vendor ID from PagerDuty")
    51  		}
    52  
    53  		if a["id"] != "PZQ6AUS" {
    54  			return fmt.Errorf("Expected the Datadog Vendor ID to be: PZQ6AUS, but got: %s", a["id"])
    55  		}
    56  
    57  		if a["name"] != "Amazon Cloudwatch" {
    58  			return fmt.Errorf("Expected the Datadog Vendor Name to be: Datadog, but got: %s", a["name"])
    59  		}
    60  
    61  		if a["type"] != "api" {
    62  			return fmt.Errorf("Expected the Datadog Vendor Type to be: api, but got: %s", a["type"])
    63  		}
    64  
    65  		return nil
    66  	}
    67  }
    68  
    69  func testAccDataSourcePagerDutyVendorLegacy(n string) resource.TestCheckFunc {
    70  	return func(s *terraform.State) error {
    71  
    72  		r := s.RootModule().Resources[n]
    73  		a := r.Primary.Attributes
    74  
    75  		if a["id"] == "" {
    76  			return fmt.Errorf("Expected to get a vendor ID from PagerDuty")
    77  		}
    78  
    79  		if a["id"] != "PAM4FGS" {
    80  			return fmt.Errorf("Expected the Datadog Vendor ID to be: PAM4FGS, but got: %s", a["id"])
    81  		}
    82  
    83  		if a["name"] != "Datadog" {
    84  			return fmt.Errorf("Expected the Datadog Vendor Name to be: Datadog, but got: %s", a["name"])
    85  		}
    86  
    87  		if a["type"] != "generic_events_api_inbound_integration" {
    88  			return fmt.Errorf("Expected the Datadog Vendor Type to be: generic_events_api_inbound_integration, but got: %s", a["type"])
    89  		}
    90  
    91  		return nil
    92  	}
    93  }
    94  
    95  const testAccDataSourcePagerDutyVendorConfig = `
    96  data "pagerduty_vendor" "foo" {
    97    name = "cloudwatch"
    98  }
    99  `
   100  
   101  const testAccDataSourcePagerDutyVendorLegacyConfig = `
   102  data "pagerduty_vendor" "foo" {
   103    name_regex = "Datadog"
   104  }
   105  `