Added some acceptance tests for the statuscake provider
This commit is contained in:
parent
038604d97d
commit
ee4d29ce97
|
@ -1,7 +1,7 @@
|
||||||
package statuscake
|
package statuscake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
wtf "github.com/DreamItGetIT/statuscake"
|
"github.com/DreamItGetIT/statuscake"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -32,9 +32,9 @@ func Provider() terraform.ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
auth := wtf.Auth{
|
auth := statuscake.Auth{
|
||||||
Username: d.Get("username").(string),
|
Username: d.Get("username").(string),
|
||||||
Apikey: d.Get("apikey").(string),
|
Apikey: d.Get("apikey").(string),
|
||||||
}
|
}
|
||||||
return wtf.New(auth)
|
return statuscake.New(auth)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
wtf "github.com/DreamItGetIT/statuscake"
|
"github.com/DreamItGetIT/statuscake"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ func resourceStatusCakeTest() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTest(d *schema.ResourceData, meta interface{}) error {
|
func CreateTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
client := meta.(*wtf.Client)
|
client := meta.(*statuscake.Client)
|
||||||
|
|
||||||
newTest := &wtf.Test{
|
newTest := &statuscake.Test{
|
||||||
WebsiteName: d.Get("website_name").(string),
|
WebsiteName: d.Get("website_name").(string),
|
||||||
WebsiteURL: d.Get("website_url").(string),
|
WebsiteURL: d.Get("website_url").(string),
|
||||||
TestType: d.Get("test_type").(string),
|
TestType: d.Get("test_type").(string),
|
||||||
|
@ -81,7 +81,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTest(d *schema.ResourceData, meta interface{}) error {
|
func UpdateTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
client := meta.(*wtf.Client)
|
client := meta.(*statuscake.Client)
|
||||||
|
|
||||||
params := getStatusCakeTestInput(d)
|
params := getStatusCakeTestInput(d)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ func UpdateTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTest(d *schema.ResourceData, meta interface{}) error {
|
func DeleteTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
client := meta.(*wtf.Client)
|
client := meta.(*statuscake.Client)
|
||||||
|
|
||||||
testId, parseErr := strconv.Atoi(d.Id())
|
testId, parseErr := strconv.Atoi(d.Id())
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
|
@ -110,7 +110,7 @@ func DeleteTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadTest(d *schema.ResourceData, meta interface{}) error {
|
func ReadTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
client := meta.(*wtf.Client)
|
client := meta.(*statuscake.Client)
|
||||||
|
|
||||||
testId, parseErr := strconv.Atoi(d.Id())
|
testId, parseErr := strconv.Atoi(d.Id())
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
|
@ -125,12 +125,12 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatusCakeTestInput(d *schema.ResourceData) *wtf.Test {
|
func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
|
||||||
testId, parseErr := strconv.Atoi(d.Id())
|
testId, parseErr := strconv.Atoi(d.Id())
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
log.Printf("[DEBUG] Error Parsing StatusCake TestID: %s", d.Id())
|
log.Printf("[DEBUG] Error Parsing StatusCake TestID: %s", d.Id())
|
||||||
}
|
}
|
||||||
test := &wtf.Test{
|
test := &statuscake.Test{
|
||||||
TestID: testId,
|
TestID: testId,
|
||||||
}
|
}
|
||||||
if v, ok := d.GetOk("website_name"); ok {
|
if v, ok := d.GetOk("website_name"); ok {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package statuscake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/DreamItGetIT/statuscake"
|
"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 {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[rn]
|
rs, ok := s.RootModule().Resources[rn]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -38,31 +66,33 @@ func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCh
|
||||||
return fmt.Errorf("TestID not set")
|
return fmt.Errorf("TestID not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
// client := testAccProvider.Meta().(*statuscake.Client)
|
client := testAccProvider.Meta().(*statuscake.Client)
|
||||||
// gotProject, err := client.GetProject(rs.Primary.ID)
|
testId, parseErr := strconv.Atoi(rs.Primary.ID)
|
||||||
// if err != nil {
|
if parseErr != nil {
|
||||||
// return fmt.Errorf("error getting project: %s", err)
|
return fmt.Errorf("error in statuscake test CheckExists: %s", parseErr)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// *project = *gotProject
|
gotTest, err := client.Tests().Detail(testId)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting project: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*test = *gotTest
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccTestCheckDestroy(project *statuscake.Test) resource.TestCheckFunc {
|
func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
|
||||||
// return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// client := testAccProvider.Meta().(*statuscake.Client)
|
client := testAccProvider.Meta().(*statuscake.Client)
|
||||||
// // _, err := client.Tests().All()
|
err := client.Tests().Delete(test.TestID)
|
||||||
// // if err == nil {
|
if err == nil {
|
||||||
// // return fmt.Errorf("test still exists")
|
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
|
||||||
// // }
|
}
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,3 +104,13 @@ resource "statuscake_test" "google" {
|
||||||
check_rate = 300
|
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
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue