]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/commitdiff
Parameterize the contact ID used for acceptance testing
authorMat Schaffer <mat@schaffer.me>
Thu, 1 Feb 2018 07:07:31 +0000 (16:07 +0900)
committerMat Schaffer <mat@schaffer.me>
Thu, 1 Feb 2018 07:07:31 +0000 (16:07 +0900)
This allowed me to run acceptance tests on my own account.

statuscake/provider_test.go
statuscake/resource_statuscaketest_test.go

index 83045d06fb30b0236902095ceec2417d560a3d2d..81d5888154dd25b88a7aed8d5bb839e6bce056e1 100644 (file)
@@ -1,7 +1,9 @@
 package statuscake
 
 import (
+       "fmt"
        "os"
+       "strconv"
        "testing"
 
        "github.com/hashicorp/terraform/helper/schema"
@@ -10,12 +12,25 @@ import (
 
 var testAccProviders map[string]terraform.ResourceProvider
 var testAccProvider *schema.Provider
+var testContactGroupId int
 
 func init() {
        testAccProvider = Provider().(*schema.Provider)
        testAccProviders = map[string]terraform.ResourceProvider{
                "statuscake": testAccProvider,
        }
+
+       if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v == "" {
+               fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be set for acceptance tests")
+               os.Exit(1)
+       } else {
+               id, err := strconv.Atoi(v)
+               if err != nil {
+                       fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be a valid int")
+                       os.Exit(1)
+               }
+               testContactGroupId = id
+       }
 }
 
 func TestProvider(t *testing.T) {
index b727e9267572e06a767a5908a4817c1359ccd8f9..ea69756e3fd8df1da3e7e4d4a6bf013723647541 100644 (file)
@@ -19,7 +19,7 @@ func TestAccStatusCake_basic(t *testing.T) {
                CheckDestroy: testAccTestCheckDestroy(&test),
                Steps: []resource.TestStep{
                        {
-                               Config: testAccTestConfig_basic,
+                               Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId),
                                Check: resource.ComposeTestCheckFunc(
                                        testAccTestCheckExists("statuscake_test.google", &test),
                                        testAccTestCheckAttributes("statuscake_test.google", &test),
@@ -38,7 +38,7 @@ func TestAccStatusCake_tcp(t *testing.T) {
                CheckDestroy: testAccTestCheckDestroy(&test),
                Steps: []resource.TestStep{
                        {
-                               Config: testAccTestConfig_tcp,
+                               Config: fmt.Sprintf(testAccTestConfig_tcp, testContactGroupId),
                                Check: resource.ComposeTestCheckFunc(
                                        testAccTestCheckExists("statuscake_test.google", &test),
                                        testAccTestCheckAttributes("statuscake_test.google", &test),
@@ -57,7 +57,7 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
                CheckDestroy: testAccTestCheckDestroy(&test),
                Steps: []resource.TestStep{
                        {
-                               Config: testAccTestConfig_basic,
+                               Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId),
                                Check: resource.ComposeTestCheckFunc(
                                        testAccTestCheckExists("statuscake_test.google", &test),
                                ),
@@ -240,7 +240,7 @@ resource "statuscake_test" "google" {
        test_type = "HTTP"
        check_rate = 300
        timeout = 10
-       contact_id = 43402
+       contact_id = %d
        confirmations = 1
        trigger_rate = 10
 }
@@ -284,7 +284,7 @@ resource "statuscake_test" "google" {
        test_type = "TCP"
        check_rate = 300
        timeout = 10
-       contact_id = 43402
+       contact_id = %d
        confirmations = 1
        port = 80
 }