| 1 | package pvtz |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/denverdino/aliyungo/common" |
| 7 | ) |
| 8 | |
| 9 | func TestDescribeRegions(t *testing.T) { |
| 10 | client := NewTestClient() |
| 11 | |
| 12 | regions, err := client.DescribeRegions() |
| 13 | |
| 14 | t.Logf("regions: %v, %v", regions, err) |
| 15 | } |
| 16 | |
| 17 | func TestAddZone(t *testing.T) { |
| 18 | client := NewTestClient() |
| 19 | |
| 20 | checkResult, err := client.CheckZoneName(&CheckZoneNameArgs{ |
| 21 | ZoneName: "demo.com", |
| 22 | }) |
| 23 | |
| 24 | t.Logf("CheckZoneName: %v, %v", checkResult, err) |
| 25 | |
| 26 | response, err := client.AddZone(&AddZoneArgs{ |
| 27 | ZoneName: "demo.com", |
| 28 | }) |
| 29 | |
| 30 | t.Logf("AddZone: %++v, %v", response, err) |
| 31 | testDescribeZones(t) |
| 32 | |
| 33 | zoneId := response.ZoneId |
| 34 | |
| 35 | err = client.UpdateZoneRemark(&UpdateZoneRemarkArgs{ |
| 36 | ZoneId: zoneId, |
| 37 | Remark: "specialZone", |
| 38 | }) |
| 39 | t.Logf("UpdateZoneRemark: %v", err) |
| 40 | |
| 41 | testDescribeZoneRecords(t, zoneId) |
| 42 | |
| 43 | err = client.BindZoneVpc(&BindZoneVpcArgs{ |
| 44 | ZoneId: zoneId, |
| 45 | Vpcs: []VPCType{ |
| 46 | VPCType{ |
| 47 | RegionId: common.Beijing, |
| 48 | VpcId: TestVPCId, |
| 49 | }, |
| 50 | }, |
| 51 | }) |
| 52 | t.Logf("BindZoneVpc: %v", err) |
| 53 | |
| 54 | zoneInfo, err := client.DescribeZoneInfo(&DescribeZoneInfoArgs{ |
| 55 | ZoneId: zoneId, |
| 56 | }) |
| 57 | |
| 58 | t.Logf("DescribeZoneInfo: %v %v", zoneInfo, err) |
| 59 | |
| 60 | err = client.BindZoneVpc(&BindZoneVpcArgs{ |
| 61 | ZoneId: zoneId, |
| 62 | Vpcs: []VPCType{}, |
| 63 | }) |
| 64 | t.Logf("unbind ZoneVpc: %v", err) |
| 65 | |
| 66 | testDeleteZone(t, zoneId) |
| 67 | |
| 68 | } |
| 69 | |
| 70 | func testDeleteZone(t *testing.T, zoneId string) { |
| 71 | client := NewTestClient() |
| 72 | |
| 73 | err := client.DeleteZone(&DeleteZoneArgs{ |
| 74 | ZoneId: zoneId, |
| 75 | }) |
| 76 | t.Logf("DeleteZone: %v", err) |
| 77 | } |
| 78 | |
| 79 | func testDescribeZones(t *testing.T) { |
| 80 | client := NewTestClient() |
| 81 | |
| 82 | zones, err := client.DescribeZones(&DescribeZonesArgs{}) |
| 83 | |
| 84 | t.Logf("zones: %v, %v", zones, err) |
| 85 | } |
| 86 | |
| 87 | func testDescribeZoneRecords(t *testing.T, zoneId string) { |
| 88 | client := NewTestClient() |
| 89 | |
| 90 | response, err := client.AddZoneRecord(&AddZoneRecordArgs{ |
| 91 | ZoneId: zoneId, |
| 92 | Rr: "www", |
| 93 | Type: "A", |
| 94 | Ttl: 60, |
| 95 | Value: "1.1.1.1", |
| 96 | }) |
| 97 | |
| 98 | t.Logf("AddZoneRecord: %v, %v", response, err) |
| 99 | |
| 100 | if err != nil { |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | recordId := response.RecordId |
| 105 | records, err := client.DescribeZoneRecords(&DescribeZoneRecordsArgs{ |
| 106 | ZoneId: zoneId, |
| 107 | }) |
| 108 | |
| 109 | t.Logf("records: %v, %v", records, err) |
| 110 | |
| 111 | err = client.DeleteZoneRecord(&DeleteZoneRecordArgs{ |
| 112 | RecordId: recordId, |
| 113 | }) |
| 114 | t.Logf("DeleteZoneRecord: %v", err) |
| 115 | } |
| 116 | |
| 117 | func TestDescribeChangeLogs(t *testing.T) { |
| 118 | client := NewTestClient() |
| 119 | |
| 120 | changeLogs, err := client.DescribeChangeLogs(&DescribeChangeLogsArgs{}) |
| 121 | |
| 122 | t.Logf("Change logs: %v, %v", changeLogs, err) |
| 123 | } |