| 1 |
package ecs |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
func TestSnapshot(t *testing.T) { |
| 8 |
|
| 9 |
client := NewTestClient() |
| 10 |
|
| 11 |
instance, err := client.DescribeInstanceAttribute(TestInstanceId) |
| 12 |
if err != nil { |
| 13 |
t.Fatalf("Failed to DescribeInstanceAttribute for instance %s: %v", TestInstanceId, err) |
| 14 |
} |
| 15 |
|
| 16 |
args := DescribeSnapshotsArgs{} |
| 17 |
|
| 18 |
args.InstanceId = TestInstanceId |
| 19 |
args.RegionId = instance.RegionId |
| 20 |
snapshots, _, err := client.DescribeSnapshots(&args) |
| 21 |
|
| 22 |
if err != nil { |
| 23 |
t.Errorf("Failed to DescribeSnapshots for instance %s: %v", TestInstanceId, err) |
| 24 |
} |
| 25 |
|
| 26 |
for _, snapshot := range snapshots { |
| 27 |
t.Logf("Snapshot of instance %s: %++v", TestInstanceId, snapshot) |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func TestSnapshotCreationAndDeletion(t *testing.T) { |
| 32 |
if TestQuick { |
| 33 |
return |
| 34 |
} |
| 35 |
|
| 36 |
client := NewTestClient() |
| 37 |
|
| 38 |
instance, err := client.DescribeInstanceAttribute(TestInstanceId) |
| 39 |
if err != nil { |
| 40 |
t.Fatalf("Failed to DescribeInstanceAttribute for instance %s: %v", TestInstanceId, err) |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
diskArgs := DescribeDisksArgs{ |
| 45 |
InstanceId: TestInstanceId, |
| 46 |
RegionId: instance.RegionId, |
| 47 |
} |
| 48 |
|
| 49 |
disks, _, err := client.DescribeDisks(&diskArgs) |
| 50 |
if err != nil { |
| 51 |
t.Fatalf("Failed to DescribeDisks for instance %s: %v", TestInstanceId, err) |
| 52 |
} |
| 53 |
|
| 54 |
diskId := disks[0].DiskId |
| 55 |
|
| 56 |
args := CreateSnapshotArgs{ |
| 57 |
DiskId: diskId, |
| 58 |
SnapshotName: "My_Test_Snapshot", |
| 59 |
Description: "My Test Snapshot Description", |
| 60 |
ClientToken: client.GenerateClientToken(), |
| 61 |
} |
| 62 |
|
| 63 |
snapshotId, err := client.CreateSnapshot(&args) |
| 64 |
if err != nil { |
| 65 |
t.Errorf("Failed to CreateSnapshot for disk %s: %v", diskId, err) |
| 66 |
} |
| 67 |
client.WaitForSnapShotReady(instance.RegionId, snapshotId, 0) |
| 68 |
|
| 69 |
err = client.DeleteSnapshot(snapshotId) |
| 70 |
if err != nil { |
| 71 |
t.Errorf("Failed to DeleteSnapshot for disk %s: %v", diskId, err) |
| 72 |
} |
| 73 |
|
| 74 |
t.Logf("Snapshot %s is deleted successfully.", snapshotId) |
| 75 |
|
| 76 |
} |