vswitches_test.go 1.5 KB

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