From 7d96831373ec571cf0d7bcd930fd6118dc509fc2 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 22:53:16 +0900 Subject: Move template interpolation deeper into acceptance tests Since it was failing `make test` on travis. Must be a better way to go about this, but I couldn't come up with a better way that defaulting the value to avoid the error when running non-acceptance tests. --- statuscake/provider_test.go | 15 --------------- statuscake/resource_statuscaketest_test.go | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'statuscake') diff --git a/statuscake/provider_test.go b/statuscake/provider_test.go index 81d5888..83045d0 100644 --- a/statuscake/provider_test.go +++ b/statuscake/provider_test.go @@ -1,9 +1,7 @@ package statuscake import ( - "fmt" "os" - "strconv" "testing" "github.com/hashicorp/terraform/helper/schema" @@ -12,25 +10,12 @@ 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 da3a349..8bcbb36 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -2,6 +2,7 @@ package statuscake import ( "fmt" + "os" "strconv" "testing" @@ -19,7 +20,7 @@ func TestAccStatusCake_basic(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), + Config: interpolateTerraformTemplate(testAccTestConfig_basic), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), testAccTestCheckAttributes("statuscake_test.google", &test), @@ -38,7 +39,7 @@ func TestAccStatusCake_tcp(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccTestConfig_tcp, testContactGroupId), + Config: interpolateTerraformTemplate(testAccTestConfig_tcp), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), testAccTestCheckAttributes("statuscake_test.google", &test), @@ -57,7 +58,7 @@ func TestAccStatusCake_withUpdate(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), + Config: interpolateTerraformTemplate(testAccTestConfig_basic), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), ), @@ -212,6 +213,19 @@ func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { } } +func interpolateTerraformTemplate(template string) string { + testContactGroupId := 43402 + + if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v != "" { + id, err := strconv.Atoi(v) + if err == nil { + testContactGroupId = id + } + } + + return fmt.Sprintf(template, testContactGroupId) +} + const testAccTestConfig_basic = ` resource "statuscake_test" "google" { website_name = "google.com" -- cgit v1.2.3