Skip to content

Commit

Permalink
testcase: Adds a new test case for resource alicloud_alb_server_group
Browse files Browse the repository at this point in the history
  • Loading branch information
thisnihonglei committed Dec 30, 2021
1 parent d557878 commit 5086523
Showing 1 changed file with 181 additions and 0 deletions.
181 changes: 181 additions & 0 deletions alicloud/resource_alicloud_alb_server_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,128 @@ func TestAccAlicloudALBServerGroup_basic1(t *testing.T) {
})
}

func TestAccAlicloudALBServerGroup_basic2(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_alb_server_group.default"
ra := resourceAttrInit(resourceId, AlicloudALBServerGroupMap0)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &AlbService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeAlbServerGroup")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%salbservergroup%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudALBServerGroupBasicDependence3)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, connectivity.AlbSupportRegions)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"protocol": "HTTP",
"vpc_id": "${alicloud_vpc.default.id}",
"server_group_name": "${var.name}",
"health_check_config": []map[string]interface{}{
{
"health_check_enabled": "false",
},
},
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.0.id}",
"dry_run": "false",
"sticky_session_config": []map[string]interface{}{
{
"cookie": "tf-testAcc",
"sticky_session_enabled": "true",
"sticky_session_type": "Server",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"protocol": "HTTP",
"server_group_name": name,
"sticky_session_config.#": "1",
"health_check_config.#": "1",
"resource_group_id": CHECKSET,
"dry_run": "false",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true, ImportStateVerifyIgnore: []string{"dry_run"},
},
},
})
}

func TestAccAlicloudALBServerGroup_basic3(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_alb_server_group.default"
ra := resourceAttrInit(resourceId, AlicloudALBServerGroupMap0)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &AlbService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeAlbServerGroup")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%salbservergroup%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudALBServerGroupBasicDependence3)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, connectivity.AlbSupportRegions)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"protocol": "HTTP",
"vpc_id": "${alicloud_vpc.default.id}",
"server_group_name": "${var.name}",
"health_check_config": []map[string]interface{}{
{
"health_check_enabled": "false",
},
},
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.0.id}",
"dry_run": "false",
"sticky_session_config": []map[string]interface{}{
{
"cookie_timeout": "2000",
"sticky_session_enabled": "true",
"sticky_session_type": "Insert",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"protocol": "HTTP",
"server_group_name": name,
"sticky_session_config.#": "1",
"health_check_config.#": "1",
"resource_group_id": CHECKSET,
"dry_run": "false",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true, ImportStateVerifyIgnore: []string{"dry_run"},
},
},
})
}

var AlicloudALBServerGroupMap0 = map[string]string{
"tags.%": NOSET,
"dry_run": NOSET,
Expand Down Expand Up @@ -511,3 +633,62 @@ resource "alicloud_instance" "instance" {
`, name)

}

func AlicloudALBServerGroupBasicDependence3(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
}
data "alicloud_zones" "default" {
available_disk_category = "cloud_efficiency"
available_resource_creation = "VSwitch"
}
data "alicloud_instance_types" "default" {
availability_zone = data.alicloud_zones.default.zones[0].id
cpu_core_count = 1
memory_size = 2
}
data "alicloud_images" "default" {
name_regex = "^ubuntu_18.*64"
most_recent = true
owners = "system"
}
resource "alicloud_vpc" "default" {
vpc_name = var.name
cidr_block = "172.16.0.0/16"
}
resource "alicloud_vswitch" "default" {
vpc_id = alicloud_vpc.default.id
cidr_block = "172.16.0.0/16"
zone_id = data.alicloud_zones.default.zones[0].id
vswitch_name = var.name
}
resource "alicloud_security_group" "default" {
name = var.name
vpc_id = alicloud_vpc.default.id
}
resource "alicloud_instance" "instance" {
image_id = data.alicloud_images.default.images[0].id
instance_type = data.alicloud_instance_types.default.instance_types[0].id
instance_name = var.name
security_groups = alicloud_security_group.default.*.id
internet_charge_type = "PayByTraffic"
internet_max_bandwidth_out = "10"
availability_zone = data.alicloud_zones.default.zones[0].id
instance_charge_type = "PostPaid"
system_disk_category = "cloud_efficiency"
vswitch_id = alicloud_vswitch.default.id
}
data "alicloud_resource_manager_resource_groups" "default" {}
`, name)

}

0 comments on commit 5086523

Please sign in to comment.