github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/pagerduty/resource_pagerduty_team_test.go (about)

     1  package pagerduty
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/PagerDuty/go-pagerduty"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  	"github.com/hashicorp/terraform/terraform"
    10  )
    11  
    12  func TestAccPagerDutyTeam_Basic(t *testing.T) {
    13  	resource.Test(t, resource.TestCase{
    14  		PreCheck:     func() { testAccPreCheck(t) },
    15  		Providers:    testAccProviders,
    16  		CheckDestroy: testAccCheckPagerDutyTeamDestroy,
    17  		Steps: []resource.TestStep{
    18  			resource.TestStep{
    19  				Config: testAccCheckPagerDutyTeamConfig,
    20  				Check: resource.ComposeTestCheckFunc(
    21  					testAccCheckPagerDutyTeamExists("pagerduty_team.foo"),
    22  					resource.TestCheckResourceAttr(
    23  						"pagerduty_team.foo", "name", "foo"),
    24  					resource.TestCheckResourceAttr(
    25  						"pagerduty_team.foo", "description", "foo"),
    26  				),
    27  			},
    28  			resource.TestStep{
    29  				Config: testAccCheckPagerDutyTeamConfigUpdated,
    30  				Check: resource.ComposeTestCheckFunc(
    31  					testAccCheckPagerDutyTeamExists("pagerduty_team.foo"),
    32  					resource.TestCheckResourceAttr(
    33  						"pagerduty_team.foo", "name", "bar"),
    34  					resource.TestCheckResourceAttr(
    35  						"pagerduty_team.foo", "description", "bar"),
    36  				),
    37  			},
    38  		},
    39  	})
    40  }
    41  
    42  func testAccCheckPagerDutyTeamDestroy(s *terraform.State) error {
    43  	client := testAccProvider.Meta().(*pagerduty.Client)
    44  	for _, r := range s.RootModule().Resources {
    45  		if r.Type != "pagerduty_team" {
    46  			continue
    47  		}
    48  
    49  		_, err := client.GetTeam(r.Primary.ID)
    50  
    51  		if err == nil {
    52  			return fmt.Errorf("Team still exists")
    53  		}
    54  
    55  	}
    56  	return nil
    57  }
    58  
    59  func testAccCheckPagerDutyTeamExists(n string) resource.TestCheckFunc {
    60  	return func(s *terraform.State) error {
    61  		client := testAccProvider.Meta().(*pagerduty.Client)
    62  		for _, r := range s.RootModule().Resources {
    63  			if _, err := client.GetTeam(r.Primary.ID); err != nil {
    64  				return fmt.Errorf("Received an error retrieving team %s ID: %s", err, r.Primary.ID)
    65  			}
    66  		}
    67  		return nil
    68  	}
    69  }
    70  
    71  const testAccCheckPagerDutyTeamConfig = `
    72  resource "pagerduty_team" "foo" {
    73    name        = "foo"
    74    description = "foo"
    75  }
    76  `
    77  
    78  const testAccCheckPagerDutyTeamConfigUpdated = `
    79  resource "pagerduty_team" "foo" {
    80    name        = "bar"
    81    description = "bar"
    82  }
    83  `