From 4eeeab6482a659f2a3c4077a38bb3c83967666ac Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 8 Oct 2015 15:36:11 +0100 Subject: Added some acceptance tests for the statuscake provider --- resource_statuscaketest_test.go | 82 ++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 21 deletions(-) (limited to 'resource_statuscaketest_test.go') diff --git a/resource_statuscaketest_test.go b/resource_statuscaketest_test.go index 8bbd4b5..f5b47e4 100644 --- a/resource_statuscaketest_test.go +++ b/resource_statuscaketest_test.go @@ -2,6 +2,7 @@ package statuscake import ( "fmt" + "strconv" "testing" "github.com/DreamItGetIT/statuscake" @@ -27,7 +28,34 @@ func TestAccStatusCake_basic(t *testing.T) { }) } -func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCheckFunc { +func TestAccStatusCake_withUpdate(t *testing.T) { + var test statuscake.Test + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccTestCheckDestroy(&test), + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccTestConfig_basic, + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + ), + }, + + resource.TestStep{ + Config: testAccTestConfig_update, + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"), + resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"), + ), + }, + }, + }) +} + +func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[rn] if !ok { @@ -38,31 +66,33 @@ func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCh return fmt.Errorf("TestID not set") } - // client := testAccProvider.Meta().(*statuscake.Client) - // gotProject, err := client.GetProject(rs.Primary.ID) - // if err != nil { - // return fmt.Errorf("error getting project: %s", err) - // } - // - // *project = *gotProject + client := testAccProvider.Meta().(*statuscake.Client) + testId, parseErr := strconv.Atoi(rs.Primary.ID) + if parseErr != nil { + return fmt.Errorf("error in statuscake test CheckExists: %s", parseErr) + } + + gotTest, err := client.Tests().Detail(testId) + if err != nil { + return fmt.Errorf("error getting project: %s", err) + } + + *test = *gotTest return nil } } -func testAccTestCheckDestroy(project *statuscake.Test) resource.TestCheckFunc { - // return func(s *terraform.State) error { - // client := testAccProvider.Meta().(*statuscake.Client) - // // _, err := client.Tests().All() - // // if err == nil { - // // return fmt.Errorf("test still exists") - // // } - // // if _, ok := err.(*statuscake.NotFoundError); !ok { - // // return fmt.Errorf("got something other than NotFoundError (%v) when getting test", err) - // // } - // - // return nil - // } +func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*statuscake.Client) + err := client.Tests().Delete(test.TestID) + if err == nil { + return fmt.Errorf("test still exists") + } + + return nil + } return nil } @@ -74,3 +104,13 @@ resource "statuscake_test" "google" { check_rate = 300 } ` + +const testAccTestConfig_update = ` +resource "statuscake_test" "google" { + website_name = "google.com" + website_url = "www.google.com" + test_type = "HTTP" + check_rate = 500 + paused = true +} +` -- cgit v1.2.3