| 1 |
package ess |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/denverdino/aliyungo/common" |
| 7 |
) |
| 8 |
|
| 9 |
func TestEssScalingConfigurationCreationAndDeletion(t *testing.T) { |
| 10 |
|
| 11 |
if TestIAmRich == false { |
| 12 |
|
| 13 |
return |
| 14 |
} |
| 15 |
|
| 16 |
client := NewTestClient(common.Region(RegionId)) |
| 17 |
ecsClient := NewTestEcsClient(common.Region(RegionId)) |
| 18 |
|
| 19 |
ecs, err := ecsClient.DescribeInstanceAttribute(TestInstanceId) |
| 20 |
if err != nil { |
| 21 |
t.Fatalf("Failed to describe ecs %s: %v", TestInstanceId, err) |
| 22 |
} |
| 23 |
t.Logf("ECS instance: %++v %v", ecs, err) |
| 24 |
|
| 25 |
cArgs := CreateScalingConfigurationArgs{ |
| 26 |
ScalingGroupId: ScalingGroupId, |
| 27 |
ImageId: ecs.ImageId, |
| 28 |
InstanceType: ecs.InstanceType, |
| 29 |
SecurityGroupId: ecs.SecurityGroupIds.SecurityGroupId[0], |
| 30 |
} |
| 31 |
|
| 32 |
csc, err := client.CreateScalingConfiguration(&cArgs) |
| 33 |
if err != nil { |
| 34 |
t.Errorf("Failed to create scaling configuration %v", err) |
| 35 |
} |
| 36 |
configurationId := csc.ScalingConfigurationId |
| 37 |
t.Logf("Configuration %s is created successfully.", configurationId) |
| 38 |
|
| 39 |
sArgs := DescribeScalingConfigurationsArgs{ |
| 40 |
RegionId: RegionId, |
| 41 |
ScalingGroupId: ScalingGroupId, |
| 42 |
ScalingConfigurationId: []string{configurationId}, |
| 43 |
} |
| 44 |
sResp, _, err := client.DescribeScalingConfigurations(&sArgs) |
| 45 |
if len(sResp) < 1 { |
| 46 |
t.Fatalf("Failed to describe confituration %s", configurationId) |
| 47 |
} |
| 48 |
|
| 49 |
config := sResp[0] |
| 50 |
t.Logf("Configuration: %++v %v", config, err) |
| 51 |
|
| 52 |
dcArgs := DeleteScalingConfigurationArgs{ |
| 53 |
ScalingGroupId: ScalingGroupId, |
| 54 |
ScalingConfigurationId: configurationId, |
| 55 |
ImageId: config.ImageId, |
| 56 |
} |
| 57 |
|
| 58 |
_, err = client.DeleteScalingConfiguration(&dcArgs) |
| 59 |
if err != nil { |
| 60 |
t.Errorf("Failed to delete scaling configuration %v", err) |
| 61 |
} |
| 62 |
|
| 63 |
t.Logf("Configuration %s is deleted successfully.", configurationId) |
| 64 |
|
| 65 |
} |