Skip to content

Commit

Permalink
Add test for update LoadBalancerAttachement
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericBerot-Armand authored and outscale-toa committed Oct 24, 2024
1 parent e61e71f commit a846569
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion outscale/resource_outscale_load_balancer_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestAccVM_WithLBUAttachment_basic(t *testing.T) {
var conf oscgo.LoadBalancer
omi := os.Getenv("OUTSCALE_IMAGEID")
rand := acctest.RandIntRange(0, 50)
region := utils.GetRegion()
testCheckInstanceAttached := func(count int) resource.TestCheckFunc {
return func(*terraform.State) error {
if conf.BackendVmIds != nil {
Expand All @@ -37,7 +38,20 @@ func TestAccVM_WithLBUAttachment_basic(t *testing.T) {
CheckDestroy: testAccCheckOutscaleLBUDestroy,
Steps: []resource.TestStep{
{
Config: testAccOutscaleLBUAttachmentConfig1(rand, omi, utils.GetRegion()),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleOAPILBUExists("outscale_load_balancer.bar", &conf),
testCheckInstanceAttached(1),
),
},
{
Config: testAcc_ConfigLBUAttachmentAddUpdate(omi, region),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleOAPILBUExists("outscale_load_balancer.bar", &conf),
testCheckInstanceAttached(2),
),
},
{
Config: testAcc_ConfigLBUAttachmentRemoveUpdate(omi, region),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleLBUExists("outscale_load_balancer.barTach", &conf),
testCheckInstanceAttached(1),
Expand Down Expand Up @@ -197,3 +211,63 @@ resource "outscale_load_balancer_vms" "foo1" {
}
`, region, omi)
}

func testAcc_ConfigLBUAttachmentAddUpdate(omi, region string) string {
return fmt.Sprintf(`
resource "outscale_load_balancer" "bar" {
load_balancer_name = "load-test12"
subregion_names = ["%sa"]
listeners {
backend_port = 8000
backend_protocol = "HTTP"
load_balancer_port = 80
load_balancer_protocol = "HTTP"
}
}
resource "outscale_vm" "foo1" {
image_id = "%[2]s"
vm_type = "tinav4.c1r1p1"
}
resource "outscale_vm" "foo2" {
image_id = "%[2]s"
vm_type = "tinav4.c1r1p1"
}
resource "outscale_load_balancer_vms" "foo1" {
load_balancer_name = "${outscale_load_balancer.bar.id}"
backend_vm_ids = ["${outscale_vm.foo1.id}", "${outscale_vm.foo2.id}"]
}
`, region, omi)
}

func testAcc_ConfigLBUAttachmentRemoveUpdate(omi, region string) string {
return fmt.Sprintf(`
resource "outscale_load_balancer" "bar" {
load_balancer_name = "load-test12"
subregion_names = ["%sa"]
listeners {
backend_port = 8000
backend_protocol = "HTTP"
load_balancer_port = 80
load_balancer_protocol = "HTTP"
}
}
resource "outscale_vm" "foo1" {
image_id = "%[2]s"
vm_type = "tinav4.c1r1p1"
}
resource "outscale_vm" "foo2" {
image_id = "%[2]s"
vm_type = "tinav4.c1r1p1"
}
resource "outscale_load_balancer_vms" "foo1" {
load_balancer_name = "${outscale_load_balancer.bar.id}"
backend_vm_ids = ["${outscale_vm.foo2.id}"]
}
`, region, omi)
}

0 comments on commit a846569

Please sign in to comment.