forked from russellcardullo/terraform-provider-pingdom
-
Notifications
You must be signed in to change notification settings - Fork 8
/
resource_pingdom_team_test.go
135 lines (119 loc) · 3.37 KB
/
resource_pingdom_team_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package pingdom
import (
"fmt"
"strconv"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccResourcePingdomTeam_basic(t *testing.T) {
resourceName := "pingdom_team.test"
contact1ResourceName := "pingdom_contact.test"
contact2ResourceName := "pingdom_contact.test_update"
name := acctest.RandomWithPrefix("tf-acc-test")
updatedName := acctest.RandomWithPrefix("tf-acc-test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPingdomTeamDestroy,
Steps: []resource.TestStep{
{
Config: testAccResourcePingdomTeamConfig(name),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckPingdomResourceID(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "member_ids.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "member_ids.0", contact1ResourceName, "id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccResourcePingdomTeamConfigUpdate(updatedName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckPingdomResourceID(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", updatedName),
resource.TestCheckResourceAttr(resourceName, "member_ids.#", "2"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "member_ids.*", contact1ResourceName, "id"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "member_ids.*", contact2ResourceName, "id"),
),
},
},
})
}
func testAccCheckPingdomTeamDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*Clients).Pingdom
for _, rs := range s.RootModule().Resources {
if rs.Type != "pingdom_team" {
continue
}
id, err := strconv.Atoi(rs.Primary.ID)
if err != nil {
return fmt.Errorf("Team ID is not valid: %s", rs.Primary.ID)
}
resp, err := client.Teams.Read(id)
if err == nil {
if strconv.Itoa(resp.ID) == rs.Primary.ID {
return fmt.Errorf("Team (%s) still exists.", rs.Primary.ID)
}
}
if !strings.Contains(err.Error(), "404") {
return err
}
}
return nil
}
func testAccResourcePingdomTeamConfig(name string) string {
return fmt.Sprintf(`
resource "pingdom_contact" "test" {
name = "tf-acc-test-pingdom-contact1"
sms_notification {
number = "66666666"
severity = "HIGH"
}
sms_notification {
number = "88888888"
severity = "LOW"
}
}
resource "pingdom_team" "test" {
name = "%s"
member_ids = [pingdom_contact.test.id]
}
`, name)
}
func testAccResourcePingdomTeamConfigUpdate(name string) string {
return fmt.Sprintf(`
resource "pingdom_contact" "test" {
name = "tf-acc-test-pingdom-contact1"
sms_notification {
number = "66666666"
severity = "HIGH"
}
sms_notification {
number = "88888888"
severity = "LOW"
}
}
resource "pingdom_contact" "test_update" {
name = "tf-acc-test-pingdom-contact2"
sms_notification {
number = "66666666"
severity = "HIGH"
}
sms_notification {
number = "88888888"
severity = "LOW"
}
}
resource "pingdom_team" "test" {
name = "%s"
member_ids = [pingdom_contact.test.id, pingdom_contact.test_update.id]
}
`, name)
}