| 1 | package ecs |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/denverdino/aliyungo/common" |
| 7 | ) |
| 8 | |
| 9 | func testCreateVSwitch(t *testing.T, client *Client, regionId common.Region, zoneId string, vpcId string, vrouterId string) (vSwitchId string, err error) { |
| 10 | |
| 11 | args := CreateVSwitchArgs{ |
| 12 | ZoneId: zoneId, |
| 13 | CidrBlock: "172.16.10.0/24", |
| 14 | VpcId: vpcId, |
| 15 | VSwitchName: "AliyunGo_test_vSwitch", |
| 16 | Description: "AliyunGo test vSwitch", |
| 17 | ClientToken: client.GenerateClientToken(), |
| 18 | } |
| 19 | |
| 20 | vSwitchId, err = client.CreateVSwitch(&args) |
| 21 | |
| 22 | if err != nil { |
| 23 | t.Errorf("Failed to create VSwitch: %v", err) |
| 24 | return "", err |
| 25 | } |
| 26 | |
| 27 | t.Logf("VSwitch is created successfully: %s", vSwitchId) |
| 28 | |
| 29 | err = client.WaitForVSwitchAvailable(vpcId, vSwitchId, 60) |
| 30 | if err != nil { |
| 31 | t.Errorf("Failed to wait VSwitch %s to available: %v", vSwitchId, err) |
| 32 | } |
| 33 | |
| 34 | newName := args.VSwitchName + "_update" |
| 35 | modifyArgs := ModifyVSwitchAttributeArgs{ |
| 36 | VSwitchId: vSwitchId, |
| 37 | VSwitchName: newName, |
| 38 | Description: newName, |
| 39 | } |
| 40 | |
| 41 | err = client.ModifyVSwitchAttribute(&modifyArgs) |
| 42 | if err != nil { |
| 43 | t.Errorf("Failed to modify VSwitch %s: %v", vSwitchId, err) |
| 44 | } |
| 45 | |
| 46 | argsDescribe := DescribeVSwitchesArgs{ |
| 47 | VpcId: vpcId, |
| 48 | VSwitchId: vSwitchId, |
| 49 | } |
| 50 | |
| 51 | vswitches, _, err := client.DescribeVSwitches(&argsDescribe) |
| 52 | if err != nil { |
| 53 | t.Errorf("Failed to describe VSwitch: %v", err) |
| 54 | } |
| 55 | |
| 56 | if vswitches[0].VSwitchName != newName { |
| 57 | t.Errorf("Failed to modify VSwitch with new name: %s", newName) |
| 58 | } |
| 59 | |
| 60 | t.Logf("VSwitch is : %++v", vswitches) |
| 61 | |
| 62 | return vSwitchId, err |
| 63 | } |