From aa4f9726b4fd3cc624fe5784b033840a6c92c84c Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:07:31 +0900 Subject: Parameterize the contact ID used for acceptance testing This allowed me to run acceptance tests on my own account. --- statuscake/provider_test.go | 15 +++++++++++++++ statuscake/resource_statuscaketest_test.go | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/statuscake/provider_test.go b/statuscake/provider_test.go index 83045d0..81d5888 100644 --- a/statuscake/provider_test.go +++ b/statuscake/provider_test.go @@ -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) { diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index b727e92..ea69756 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -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 } -- cgit v1.2.3