diff options
author | stack72 <public@paulstack.co.uk> | 2015-10-08 15:36:11 +0100 |
---|---|---|
committer | stack72 <public@paulstack.co.uk> | 2015-11-27 15:03:13 +0000 |
commit | 4eeeab6482a659f2a3c4077a38bb3c83967666ac (patch) | |
tree | c95f8cce5f85acca80faac104130dd3e55dc83f8 /resource_statuscaketest_test.go | |
parent | 32574941630dadbe86b887c174e1b7bcfd9580c1 (diff) | |
download | terraform-provider-statuscake-4eeeab6482a659f2a3c4077a38bb3c83967666ac.tar.gz terraform-provider-statuscake-4eeeab6482a659f2a3c4077a38bb3c83967666ac.tar.zst terraform-provider-statuscake-4eeeab6482a659f2a3c4077a38bb3c83967666ac.zip |
Added some acceptance tests for the statuscake provider
Diffstat (limited to 'resource_statuscaketest_test.go')
-rw-r--r-- | resource_statuscaketest_test.go | 82 |
1 files changed, 61 insertions, 21 deletions
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 | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "strconv" | ||
5 | "testing" | 6 | "testing" |
6 | 7 | ||
7 | "github.com/DreamItGetIT/statuscake" | 8 | "github.com/DreamItGetIT/statuscake" |
@@ -27,7 +28,34 @@ func TestAccStatusCake_basic(t *testing.T) { | |||
27 | }) | 28 | }) |
28 | } | 29 | } |
29 | 30 | ||
30 | func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCheckFunc { | 31 | func TestAccStatusCake_withUpdate(t *testing.T) { |
32 | var test statuscake.Test | ||
33 | |||
34 | resource.Test(t, resource.TestCase{ | ||
35 | PreCheck: func() { testAccPreCheck(t) }, | ||
36 | Providers: testAccProviders, | ||
37 | CheckDestroy: testAccTestCheckDestroy(&test), | ||
38 | Steps: []resource.TestStep{ | ||
39 | resource.TestStep{ | ||
40 | Config: testAccTestConfig_basic, | ||
41 | Check: resource.ComposeTestCheckFunc( | ||
42 | testAccTestCheckExists("statuscake_test.google", &test), | ||
43 | ), | ||
44 | }, | ||
45 | |||
46 | resource.TestStep{ | ||
47 | Config: testAccTestConfig_update, | ||
48 | Check: resource.ComposeTestCheckFunc( | ||
49 | testAccTestCheckExists("statuscake_test.google", &test), | ||
50 | resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"), | ||
51 | resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"), | ||
52 | ), | ||
53 | }, | ||
54 | }, | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { | ||
31 | return func(s *terraform.State) error { | 59 | return func(s *terraform.State) error { |
32 | rs, ok := s.RootModule().Resources[rn] | 60 | rs, ok := s.RootModule().Resources[rn] |
33 | if !ok { | 61 | if !ok { |
@@ -38,31 +66,33 @@ func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCh | |||
38 | return fmt.Errorf("TestID not set") | 66 | return fmt.Errorf("TestID not set") |
39 | } | 67 | } |
40 | 68 | ||
41 | // client := testAccProvider.Meta().(*statuscake.Client) | 69 | client := testAccProvider.Meta().(*statuscake.Client) |
42 | // gotProject, err := client.GetProject(rs.Primary.ID) | 70 | testId, parseErr := strconv.Atoi(rs.Primary.ID) |
43 | // if err != nil { | 71 | if parseErr != nil { |
44 | // return fmt.Errorf("error getting project: %s", err) | 72 | return fmt.Errorf("error in statuscake test CheckExists: %s", parseErr) |
45 | // } | 73 | } |
46 | // | 74 | |
47 | // *project = *gotProject | 75 | gotTest, err := client.Tests().Detail(testId) |
76 | if err != nil { | ||
77 | return fmt.Errorf("error getting project: %s", err) | ||
78 | } | ||
79 | |||
80 | *test = *gotTest | ||
48 | 81 | ||
49 | return nil | 82 | return nil |
50 | } | 83 | } |
51 | } | 84 | } |
52 | 85 | ||
53 | func testAccTestCheckDestroy(project *statuscake.Test) resource.TestCheckFunc { | 86 | func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { |
54 | // return func(s *terraform.State) error { | 87 | return func(s *terraform.State) error { |
55 | // client := testAccProvider.Meta().(*statuscake.Client) | 88 | client := testAccProvider.Meta().(*statuscake.Client) |
56 | // // _, err := client.Tests().All() | 89 | err := client.Tests().Delete(test.TestID) |
57 | // // if err == nil { | 90 | if err == nil { |
58 | // // return fmt.Errorf("test still exists") | 91 | return fmt.Errorf("test still exists") |
59 | // // } | 92 | } |
60 | // // if _, ok := err.(*statuscake.NotFoundError); !ok { | 93 | |
61 | // // return fmt.Errorf("got something other than NotFoundError (%v) when getting test", err) | 94 | return nil |
62 | // // } | 95 | } |
63 | // | ||
64 | // return nil | ||
65 | // } | ||
66 | return nil | 96 | return nil |
67 | } | 97 | } |
68 | 98 | ||
@@ -74,3 +104,13 @@ resource "statuscake_test" "google" { | |||
74 | check_rate = 300 | 104 | check_rate = 300 |
75 | } | 105 | } |
76 | ` | 106 | ` |
107 | |||
108 | const testAccTestConfig_update = ` | ||
109 | resource "statuscake_test" "google" { | ||
110 | website_name = "google.com" | ||
111 | website_url = "www.google.com" | ||
112 | test_type = "HTTP" | ||
113 | check_rate = 500 | ||
114 | paused = true | ||
115 | } | ||
116 | ` | ||