File: vswitches_test.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (63 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (3)
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
}