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
|
package ecs
import (
"testing"
"github.com/denverdino/aliyungo/common"
)
func testCreateVSwitch(t *testing.T, client *Client, regionId common.Region, zoneId string, vpcId string, vrouterId string) (vSwitchId string, err error) {
args := CreateVSwitchArgs{
ZoneId: zoneId,
CidrBlock: "172.16.10.0/24",
VpcId: vpcId,
VSwitchName: "AliyunGo_test_vSwitch",
Description: "AliyunGo test vSwitch",
ClientToken: client.GenerateClientToken(),
}
vSwitchId, err = client.CreateVSwitch(&args)
if err != nil {
t.Errorf("Failed to create VSwitch: %v", err)
return "", err
}
t.Logf("VSwitch is created successfully: %s", vSwitchId)
err = client.WaitForVSwitchAvailable(vpcId, vSwitchId, 60)
if err != nil {
t.Errorf("Failed to wait VSwitch %s to available: %v", vSwitchId, err)
}
newName := args.VSwitchName + "_update"
modifyArgs := ModifyVSwitchAttributeArgs{
VSwitchId: vSwitchId,
VSwitchName: newName,
Description: newName,
}
err = client.ModifyVSwitchAttribute(&modifyArgs)
if err != nil {
t.Errorf("Failed to modify VSwitch %s: %v", vSwitchId, err)
}
argsDescribe := DescribeVSwitchesArgs{
VpcId: vpcId,
VSwitchId: vSwitchId,
}
vswitches, _, err := client.DescribeVSwitches(&argsDescribe)
if err != nil {
t.Errorf("Failed to describe VSwitch: %v", err)
}
if vswitches[0].VSwitchName != newName {
t.Errorf("Failed to modify VSwitch with new name: %s", newName)
}
t.Logf("VSwitch is : %++v", vswitches)
return vSwitchId, err
}
|