aboutsummaryrefslogtreecommitdiffhomepage
path: root/resource_statuscaketest_test.go
blob: 8bbd4b5ba83344ac958e6ce948d3e0cdd36689bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package statuscake

import (
	"fmt"
	"testing"

	"github.com/DreamItGetIT/statuscake"
	"github.com/hashicorp/terraform/helper/resource"
	"github.com/hashicorp/terraform/terraform"
)

func TestAccStatusCake_basic(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),
				),
			},
		},
	})
}

func testAccTestCheckExists(rn string, project *statuscake.Test) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[rn]
		if !ok {
			return fmt.Errorf("resource not found: %s", rn)
		}

		if rs.Primary.ID == "" {
			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

		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
	//	}
	return nil
}

const testAccTestConfig_basic = `
resource "statuscake_test" "google" {
  website_name = "google.com"
  website_url = "www.google.com"
  test_type = "HTTP"
  check_rate = 300
}
`