-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_clc_load_balancer_test.go
104 lines (94 loc) · 2.81 KB
/
resource_clc_load_balancer_test.go
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package clc
import (
"fmt"
"testing"
clc "github.com/CenturyLinkCloud/clc-sdk"
lb "github.com/CenturyLinkCloud/clc-sdk/lb"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
// things to test:
// updates name/desc
// toggles status
// created w/o pool
const testAccDC = "WA1"
func TestAccLoadBalancerBasic(t *testing.T) {
var resp lb.LoadBalancer
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckLBConfigBasic,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBExists("clc_load_balancer.acc_test_lb", &resp),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "name", "acc_test_lb"),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "data_center", testAccDC),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "status", "enabled"),
),
},
/*
// FIXME: cant'r figure out why this is throwing "Not Found"
// update simple attrs
resource.TestStep{
Config: testAccCheckLBConfigNameDesc,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBExists("clc_load_balancer.acc_test_lb", &resp),
resource.TestCheckResourceAttr("clc_load_balancher.acc_test_lb", "name", "foobar"),
resource.TestCheckResourceAttr("clc_load_balancher.acc_test_lb", "description", "foobar"),
resource.TestCheckResourceAttr("clc_load_balancher.acc_test_lb", "status", "disabled"),
),
},
*/
},
})
}
func testAccCheckLBDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*clc.Client)
for _, rs := range s.RootModule().Resources {
if rs.Type != "clc_load_balancer" {
continue
}
_, err := client.LB.Get(testAccDC, rs.Primary.ID)
if err == nil {
return fmt.Errorf("LB still exists")
}
}
return nil
}
func testAccCheckLBExists(n string, resp *lb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
client := testAccProvider.Meta().(*clc.Client)
l, err := client.LB.Get(testAccDC, rs.Primary.ID)
if err != nil {
return err
}
if l.ID != rs.Primary.ID {
return fmt.Errorf("LB not found")
}
*resp = *l
return nil
}
}
const testAccCheckLBConfigBasic = `
resource "clc_load_balancer" "acc_test_lb" {
data_center = "WA1"
name = "acc_test_lb"
description = "load balancer test"
status = "enabled"
}`
const testAccCheckLBConfigNameDesc = `
resource "clc_load_balancer" "acc_test_lb" {
data_center = "WA1"
name = "foobar"
description = "foobar"
status = "disabled"
}`