| 1 |
package ess |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/denverdino/aliyungo/common" |
| 7 |
"github.com/denverdino/aliyungo/util" |
| 8 |
) |
| 9 |
|
| 10 |
func TestEssScalingRuleCreationAndDeletion(t *testing.T) { |
| 11 |
|
| 12 |
if TestIAmRich == false { |
| 13 |
|
| 14 |
return |
| 15 |
} |
| 16 |
client := NewTestClient(common.Region(RegionId)) |
| 17 |
cArgs := CreateScalingRuleArgs{ |
| 18 |
RegionId: common.Region(RegionId), |
| 19 |
ScalingGroupId: ScalingGroupId, |
| 20 |
AdjustmentType: TotalCapacity, |
| 21 |
AdjustmentValue: 3, |
| 22 |
ScalingRuleName: "srn", |
| 23 |
} |
| 24 |
|
| 25 |
csc, err := client.CreateScalingRule(&cArgs) |
| 26 |
if err != nil { |
| 27 |
t.Errorf("Failed to create scaling rule %v", err) |
| 28 |
} |
| 29 |
ruleId := csc.ScalingRuleId |
| 30 |
t.Logf("Rule %s is created successfully.", ruleId) |
| 31 |
|
| 32 |
mArgs := ModifyScalingRuleArgs{ |
| 33 |
RegionId: common.Region(RegionId), |
| 34 |
ScalingRuleId: ruleId, |
| 35 |
AdjustmentValue: 2, |
| 36 |
ScalingRuleName: "srnm", |
| 37 |
} |
| 38 |
|
| 39 |
_, err = client.ModifyScalingRule(&mArgs) |
| 40 |
if err != nil { |
| 41 |
t.Errorf("Failed to modify scaling rule %v", err) |
| 42 |
} |
| 43 |
t.Logf("Rule %s is modify successfully.", ruleId) |
| 44 |
|
| 45 |
eArgs := ExecuteScalingRuleArgs{ |
| 46 |
ScalingRuleAri: csc.ScalingRuleAri, |
| 47 |
ClientToken: util.CreateRandomString(), |
| 48 |
} |
| 49 |
_, err = client.ExecuteScalingRule(&eArgs) |
| 50 |
if err != nil { |
| 51 |
t.Errorf("Failed to execute scaling rule: %v", err) |
| 52 |
} |
| 53 |
t.Logf("Rule %s is execute successfully.", ruleId) |
| 54 |
|
| 55 |
sArgs := DescribeScalingRulesArgs{ |
| 56 |
RegionId: common.Region(RegionId), |
| 57 |
ScalingGroupId: ScalingGroupId, |
| 58 |
ScalingRuleId: []string{ruleId}, |
| 59 |
} |
| 60 |
sResp, _, err := client.DescribeScalingRules(&sArgs) |
| 61 |
if len(sResp) < 1 { |
| 62 |
t.Fatalf("Failed to describe rules %s", ruleId) |
| 63 |
} |
| 64 |
|
| 65 |
rule := sResp[0] |
| 66 |
t.Logf("Rule: %++v %v", rule, err) |
| 67 |
|
| 68 |
dcArgs := DeleteScalingRuleArgs{ |
| 69 |
RegionId: common.Region(RegionId), |
| 70 |
ScalingRuleId: ruleId, |
| 71 |
} |
| 72 |
|
| 73 |
_, err = client.DeleteScalingRule(&dcArgs) |
| 74 |
if err != nil { |
| 75 |
t.Errorf("Failed to delete scaling rule %v", err) |
| 76 |
} |
| 77 |
|
| 78 |
t.Logf("Rule %s is deleted successfully.", ruleId) |
| 79 |
|
| 80 |
} |