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
|
package ess
import (
"testing"
"github.com/denverdino/aliyungo/common"
)
func TestEssScalingConfigurationCreationAndDeletion(t *testing.T) {
if TestIAmRich == false {
// Avoid payment
return
}
client := NewTestClient(common.Region(RegionId))
ecsClient := NewTestEcsClient(common.Region(RegionId))
ecs, err := ecsClient.DescribeInstanceAttribute(TestInstanceId)
if err != nil {
t.Fatalf("Failed to describe ecs %s: %v", TestInstanceId, err)
}
t.Logf("ECS instance: %++v %v", ecs, err)
cArgs := CreateScalingConfigurationArgs{
ScalingGroupId: ScalingGroupId,
ImageId: ecs.ImageId,
InstanceType: ecs.InstanceType,
SecurityGroupId: ecs.SecurityGroupIds.SecurityGroupId[0],
}
csc, err := client.CreateScalingConfiguration(&cArgs)
if err != nil {
t.Errorf("Failed to create scaling configuration %v", err)
}
configurationId := csc.ScalingConfigurationId
t.Logf("Configuration %s is created successfully.", configurationId)
sArgs := DescribeScalingConfigurationsArgs{
RegionId: RegionId,
ScalingGroupId: ScalingGroupId,
ScalingConfigurationId: []string{configurationId},
}
sResp, _, err := client.DescribeScalingConfigurations(&sArgs)
if len(sResp) < 1 {
t.Fatalf("Failed to describe confituration %s", configurationId)
}
config := sResp[0]
t.Logf("Configuration: %++v %v", config, err)
dcArgs := DeleteScalingConfigurationArgs{
ScalingGroupId: ScalingGroupId,
ScalingConfigurationId: configurationId,
ImageId: config.ImageId,
}
_, err = client.DeleteScalingConfiguration(&dcArgs)
if err != nil {
t.Errorf("Failed to delete scaling configuration %v", err)
}
t.Logf("Configuration %s is deleted successfully.", configurationId)
}
|