2016-01-28 01:48:44 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// update simple attrs
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccCheckLBConfigNameDesc,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckLBExists("clc_load_balancer.acc_test_lb", &resp),
|
|
|
|
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "name", "foobar"),
|
|
|
|
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "description", "foobar"),
|
|
|
|
resource.TestCheckResourceAttr("clc_load_balancer.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
|
|
|
|
}
|
2016-03-21 22:38:43 +01:00
|
|
|
if _, err := client.LB.Get(testAccDC, rs.Primary.ID); err == nil {
|
2016-01-28 01:48:44 +01:00
|
|
|
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 = `
|
2016-03-21 22:38:43 +01:00
|
|
|
variable "dc" { default = "IL1" }
|
|
|
|
|
2016-01-28 01:48:44 +01:00
|
|
|
resource "clc_load_balancer" "acc_test_lb" {
|
2016-03-21 22:38:43 +01:00
|
|
|
data_center = "${var.dc}"
|
2016-01-28 01:48:44 +01:00
|
|
|
name = "acc_test_lb"
|
|
|
|
description = "load balancer test"
|
|
|
|
status = "enabled"
|
|
|
|
}`
|
|
|
|
|
|
|
|
const testAccCheckLBConfigNameDesc = `
|
2016-03-21 22:38:43 +01:00
|
|
|
variable "dc" { default = "IL1" }
|
|
|
|
|
2016-01-28 01:48:44 +01:00
|
|
|
resource "clc_load_balancer" "acc_test_lb" {
|
2016-03-21 22:38:43 +01:00
|
|
|
data_center = "${var.dc}"
|
2016-01-28 01:48:44 +01:00
|
|
|
name = "foobar"
|
|
|
|
description = "foobar"
|
|
|
|
status = "disabled"
|
|
|
|
}`
|