func TestSnapshotsCreateDelete(t *testing.T) { client, err := clients.NewBlockStorageV1Client() if err != nil { t.Fatalf("Unable to create a blockstorage client: %v", err) } volume, err := CreateVolume(t, client) if err != nil { t.Fatalf("Unable to create volume: %v", err) } defer DeleteVolume(t, client, volume) snapshot, err := CreateSnapshot(t, client, volume) if err != nil { t.Fatalf("Unable to create snapshot: %v", err) } defer DeleteSnapshotshot(t, client, snapshot) newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract() if err != nil { t.Errorf("Unable to retrieve snapshot: %v", err) } PrintSnapshot(t, newSnapshot) }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockGetResponse(t) v, err := snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract() th.AssertNoErr(t, err) th.AssertEquals(t, v.Name, "snapshot-001") th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") }
// DeleteSnapshot will delete a snapshot. A fatal error will occur if the // snapshot failed to be deleted. This works best when used as a deferred // function. func DeleteSnapshotshot(t *testing.T, client *gophercloud.ServiceClient, snapshot *snapshots.Snapshot) { err := snapshots.Delete(client, snapshot.ID).ExtractErr() if err != nil { t.Fatalf("Unable to delete snapshot %s: %v", snapshot.ID, err) } // Volumes can't be deleted until their snapshots have been, // so block up to 120 seconds for the snapshot to delete. err = gophercloud.WaitFor(120, func() (bool, error) { _, err := snapshots.Get(client, snapshot.ID).Extract() if err != nil { return true, nil } return false, nil }) if err != nil { t.Fatalf("Unable to wait for snapshot to delete: %v", err) } t.Logf("Deleted snapshot: %s", snapshot.ID) }