| 1 |
package ess |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/denverdino/aliyungo/common" |
| 7 |
) |
| 8 |
|
| 9 |
func TestEssScalingGroupCreationAndDeletion(t *testing.T) { |
| 10 |
|
| 11 |
if TestIAmRich == false { |
| 12 |
|
| 13 |
return |
| 14 |
} |
| 15 |
|
| 16 |
client := NewTestClient(common.Region(RegionId)) |
| 17 |
|
| 18 |
maxSize := 1 |
| 19 |
minSize := 1 |
| 20 |
|
| 21 |
args := CreateScalingGroupArgs{ |
| 22 |
RegionId: common.Region(RegionId), |
| 23 |
ScalingGroupName: "test_sg", |
| 24 |
MaxSize: &maxSize, |
| 25 |
MinSize: &minSize, |
| 26 |
RemovalPolicy: []string{"OldestInstance", "NewestInstance"}, |
| 27 |
} |
| 28 |
|
| 29 |
resp, err := client.CreateScalingGroup(&args) |
| 30 |
if err != nil { |
| 31 |
t.Errorf("Failed to create scaling group %v", err) |
| 32 |
} |
| 33 |
instanceId := resp.ScalingGroupId |
| 34 |
t.Logf("Instance %s is created successfully.", instanceId) |
| 35 |
|
| 36 |
defaultCooldown := 200 |
| 37 |
|
| 38 |
mArgs := ModifyScalingGroupArgs{ |
| 39 |
ScalingGroupId: instanceId, |
| 40 |
ScalingGroupName: "sg_modify", |
| 41 |
DefaultCooldown: &defaultCooldown, |
| 42 |
} |
| 43 |
|
| 44 |
_, err = client.ModifyScalingGroup(&mArgs) |
| 45 |
if err != nil { |
| 46 |
t.Errorf("Failed to modify scaling group %v", err) |
| 47 |
} |
| 48 |
|
| 49 |
arrtArgs := DescribeScalingGroupsArgs{ |
| 50 |
RegionId: common.Region(RegionId), |
| 51 |
ScalingGroupId: []string{instanceId}, |
| 52 |
} |
| 53 |
attrResp, _, err := client.DescribeScalingGroups(&arrtArgs) |
| 54 |
t.Logf("Instance: %++v %v", attrResp[0], err) |
| 55 |
|
| 56 |
iArgs := DescribeScalingInstancesArgs{ |
| 57 |
RegionId: common.Region(RegionId), |
| 58 |
ScalingGroupId: instanceId, |
| 59 |
} |
| 60 |
iResp, _, err := client.DescribeScalingInstances(&iArgs) |
| 61 |
if len(iResp) < 1 { |
| 62 |
t.Logf("Scaling ecs instances empty.") |
| 63 |
} else { |
| 64 |
t.Logf("ECS: %++v %v", iResp[0], err) |
| 65 |
} |
| 66 |
|
| 67 |
dArgs := DeleteScalingGroupArgs{ |
| 68 |
ScalingGroupId: instanceId, |
| 69 |
ForceDelete: true, |
| 70 |
} |
| 71 |
_, err = client.DeleteScalingGroup(&dArgs) |
| 72 |
|
| 73 |
if err != nil { |
| 74 |
t.Errorf("Failed to delete instance %s: %v", instanceId, err) |
| 75 |
} |
| 76 |
t.Logf("Instance %s is deleted successfully.", instanceId) |
| 77 |
} |