aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorstack72 <public@paulstack.co.uk>2015-10-08 15:36:11 +0100
committerstack72 <public@paulstack.co.uk>2015-11-27 15:03:13 +0000
commit4eeeab6482a659f2a3c4077a38bb3c83967666ac (patch)
treec95f8cce5f85acca80faac104130dd3e55dc83f8
parent32574941630dadbe86b887c174e1b7bcfd9580c1 (diff)
downloadterraform-provider-statuscake-4eeeab6482a659f2a3c4077a38bb3c83967666ac.tar.gz
terraform-provider-statuscake-4eeeab6482a659f2a3c4077a38bb3c83967666ac.tar.zst
terraform-provider-statuscake-4eeeab6482a659f2a3c4077a38bb3c83967666ac.zip
Added some acceptance tests for the statuscake provider
-rw-r--r--provider.go6
-rw-r--r--resource_statuscaketest.go16
-rw-r--r--resource_statuscaketest_test.go82
3 files changed, 72 insertions, 32 deletions
diff --git a/provider.go b/provider.go
index 7d96e0e..abca376 100644
--- a/provider.go
+++ b/provider.go
@@ -1,7 +1,7 @@
1package statuscake 1package statuscake
2 2
3import ( 3import (
4 wtf "github.com/DreamItGetIT/statuscake" 4 "github.com/DreamItGetIT/statuscake"
5 "github.com/hashicorp/terraform/helper/schema" 5 "github.com/hashicorp/terraform/helper/schema"
6 "github.com/hashicorp/terraform/terraform" 6 "github.com/hashicorp/terraform/terraform"
7) 7)
@@ -32,9 +32,9 @@ func Provider() terraform.ResourceProvider {
32} 32}
33 33
34func providerConfigure(d *schema.ResourceData) (interface{}, error) { 34func providerConfigure(d *schema.ResourceData) (interface{}, error) {
35 auth := wtf.Auth{ 35 auth := statuscake.Auth{
36 Username: d.Get("username").(string), 36 Username: d.Get("username").(string),
37 Apikey: d.Get("apikey").(string), 37 Apikey: d.Get("apikey").(string),
38 } 38 }
39 return wtf.New(auth) 39 return statuscake.New(auth)
40} 40}
diff --git a/resource_statuscaketest.go b/resource_statuscaketest.go
index 17488a5..7f5ff67 100644
--- a/resource_statuscaketest.go
+++ b/resource_statuscaketest.go
@@ -6,7 +6,7 @@ import (
6 6
7 "log" 7 "log"
8 8
9 wtf "github.com/DreamItGetIT/statuscake" 9 "github.com/DreamItGetIT/statuscake"
10 "github.com/hashicorp/terraform/helper/schema" 10 "github.com/hashicorp/terraform/helper/schema"
11) 11)
12 12
@@ -58,9 +58,9 @@ func resourceStatusCakeTest() *schema.Resource {
58} 58}
59 59
60func CreateTest(d *schema.ResourceData, meta interface{}) error { 60func CreateTest(d *schema.ResourceData, meta interface{}) error {
61 client := meta.(*wtf.Client) 61 client := meta.(*statuscake.Client)
62 62
63 newTest := &wtf.Test{ 63 newTest := &statuscake.Test{
64 WebsiteName: d.Get("website_name").(string), 64 WebsiteName: d.Get("website_name").(string),
65 WebsiteURL: d.Get("website_url").(string), 65 WebsiteURL: d.Get("website_url").(string),
66 TestType: d.Get("test_type").(string), 66 TestType: d.Get("test_type").(string),
@@ -81,7 +81,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
81} 81}
82 82
83func UpdateTest(d *schema.ResourceData, meta interface{}) error { 83func UpdateTest(d *schema.ResourceData, meta interface{}) error {
84 client := meta.(*wtf.Client) 84 client := meta.(*statuscake.Client)
85 85
86 params := getStatusCakeTestInput(d) 86 params := getStatusCakeTestInput(d)
87 87
@@ -94,7 +94,7 @@ func UpdateTest(d *schema.ResourceData, meta interface{}) error {
94} 94}
95 95
96func DeleteTest(d *schema.ResourceData, meta interface{}) error { 96func DeleteTest(d *schema.ResourceData, meta interface{}) error {
97 client := meta.(*wtf.Client) 97 client := meta.(*statuscake.Client)
98 98
99 testId, parseErr := strconv.Atoi(d.Id()) 99 testId, parseErr := strconv.Atoi(d.Id())
100 if parseErr != nil { 100 if parseErr != nil {
@@ -110,7 +110,7 @@ func DeleteTest(d *schema.ResourceData, meta interface{}) error {
110} 110}
111 111
112func ReadTest(d *schema.ResourceData, meta interface{}) error { 112func ReadTest(d *schema.ResourceData, meta interface{}) error {
113 client := meta.(*wtf.Client) 113 client := meta.(*statuscake.Client)
114 114
115 testId, parseErr := strconv.Atoi(d.Id()) 115 testId, parseErr := strconv.Atoi(d.Id())
116 if parseErr != nil { 116 if parseErr != nil {
@@ -125,12 +125,12 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
125 return nil 125 return nil
126} 126}
127 127
128func getStatusCakeTestInput(d *schema.ResourceData) *wtf.Test { 128func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
129 testId, parseErr := strconv.Atoi(d.Id()) 129 testId, parseErr := strconv.Atoi(d.Id())
130 if parseErr != nil { 130 if parseErr != nil {
131 log.Printf("[DEBUG] Error Parsing StatusCake TestID: %s", d.Id()) 131 log.Printf("[DEBUG] Error Parsing StatusCake TestID: %s", d.Id())
132 } 132 }
133 test := &wtf.Test{ 133 test := &statuscake.Test{
134 TestID: testId, 134 TestID: testId,
135 } 135 }
136 if v, ok := d.GetOk("website_name"); ok { 136 if v, ok := d.GetOk("website_name"); ok {
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
3import ( 3import (
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
30func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCheckFunc { 31func 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
58func 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
53func testAccTestCheckDestroy(project *statuscake.Test) resource.TestCheckFunc { 86func 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
108const testAccTestConfig_update = `
109resource "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`