@@ -2,6 +2,7 @@ package statuscake
22
33import (
44 "fmt"
5+ "os"
56 "strconv"
67 "testing"
78
@@ -10,6 +11,19 @@ import (
1011 "github.com/hashicorp/terraform/terraform"
1112)
1213
14+ // check to ensure that contact group id is provided before running
15+ // tests on it.
16+ func testAccContactGroupPreCheck (t * testing.T , testAlt bool ) {
17+ if v := os .Getenv ("CONTACT_GROUP" ); v == "" {
18+ t .Fatal ("CONTACT_GROUP must be set for contact group acceptance tests" )
19+ }
20+ if testAlt {
21+ if v := os .Getenv ("ALT_CONTACT_GROUP" ); v == "" {
22+ t .Fatal ("ALT_CONTACT_GROUP must be set for contact group acceptance tests" )
23+ }
24+ }
25+ }
26+
1327func TestAccStatusCake_basic (t * testing.T ) {
1428 var test statuscake.Test
1529
@@ -55,6 +69,57 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
5569 })
5670}
5771
72+ func TestAccStatusCake_contactGroup_basic (t * testing.T ) {
73+ var test statuscake.Test
74+
75+ resource .Test (t , resource.TestCase {
76+ PreCheck : func () {
77+ testAccPreCheck (t )
78+ testAccContactGroupPreCheck (t , false )
79+ },
80+ Providers : testAccProviders ,
81+ CheckDestroy : testAccTestCheckDestroy (& test ),
82+ Steps : []resource.TestStep {
83+ resource.TestStep {
84+ Config : testAccTestConfig_contactGroup ,
85+ Check : resource .ComposeTestCheckFunc (
86+ testAccTestCheckExists ("statuscake_test.google" , & test ),
87+ ),
88+ },
89+ },
90+ })
91+ }
92+
93+ func TestAccStatusCake_contactGroup_withUpdate (t * testing.T ) {
94+ var test statuscake.Test
95+ var altContactGroup = os .Getenv ("ALT_CONTACT_GROUP" )
96+
97+ resource .Test (t , resource.TestCase {
98+ PreCheck : func () {
99+ testAccPreCheck (t )
100+ testAccContactGroupPreCheck (t , true )
101+ },
102+ Providers : testAccProviders ,
103+ CheckDestroy : testAccTestCheckDestroy (& test ),
104+ Steps : []resource.TestStep {
105+ resource.TestStep {
106+ Config : testAccTestConfig_contactGroup ,
107+ Check : resource .ComposeTestCheckFunc (
108+ testAccTestCheckExists ("statuscake_test.google" , & test ),
109+ ),
110+ },
111+ // make sure to creat
112+ resource.TestStep {
113+ Config : testAccTestConfig_contactGroup_update ,
114+ Check : resource .ComposeTestCheckFunc (
115+ testAccTestCheckExists ("statuscake_test.google" , & test ),
116+ resource .TestCheckResourceAttr ("statuscake_test.google" , "contact_id" , altContactGroup ),
117+ ),
118+ },
119+ },
120+ })
121+ }
122+
58123func testAccTestCheckExists (rn string , test * statuscake.Test ) resource.TestCheckFunc {
59124 return func (s * terraform.State ) error {
60125 rs , ok := s .RootModule ().Resources [rn ]
@@ -113,3 +178,21 @@ resource "statuscake_test" "google" {
113178 paused = true
114179}
115180`
181+
182+ var testAccTestConfig_contactGroup string = `` +
183+ `resource "statuscake_test" "google" {
184+ website_name = "google.com"
185+ website_url = "www.google.com"
186+ test_type = "HTTP"
187+ check_rate = 300
188+ contact_id = ` + os .Getenv ("CONTACT_GROUP" ) + `
189+ }`
190+
191+ var testAccTestConfig_contactGroup_update string = `` +
192+ `resource "statuscake_test" "google" {
193+ website_name = "google.com"
194+ website_url = "www.google.com"
195+ test_type = "HTTP"
196+ check_rate = 300
197+ contact_id = ` + os .Getenv ("ALT_CONTACT_GROUP" ) + `
198+ }`
0 commit comments