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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//go:build acceptance
// +build acceptance
package v2
import (
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots"
th "github.com/gophercloud/gophercloud/testhelper"
)
func TestSnapshotCreate(t *testing.T) {
client, err := clients.NewSharedFileSystemV2Client()
if err != nil {
t.Fatalf("Unable to create a shared file system client: %v", err)
}
share, err := CreateShare(t, client)
if err != nil {
t.Fatalf("Unable to create a share: %v", err)
}
defer DeleteShare(t, client, share)
snapshot, err := CreateSnapshot(t, client, share.ID)
if err != nil {
t.Fatalf("Unable to create a snapshot: %v", err)
}
defer DeleteSnapshot(t, client, snapshot)
created, err := snapshots.Get(client, snapshot.ID).Extract()
if err != nil {
t.Fatalf("Unable to retrieve a snapshot: %v", err)
}
tools.PrintResource(t, created)
}
func TestSnapshotUpdate(t *testing.T) {
client, err := clients.NewSharedFileSystemV2Client()
if err != nil {
t.Fatalf("Unable to create shared file system client: %v", err)
}
share, err := CreateShare(t, client)
if err != nil {
t.Fatalf("Unable to create share: %v", err)
}
defer DeleteShare(t, client, share)
snapshot, err := CreateSnapshot(t, client, share.ID)
if err != nil {
t.Fatalf("Unable to create a snapshot: %v", err)
}
defer DeleteSnapshot(t, client, snapshot)
expectedSnapshot, err := snapshots.Get(client, snapshot.ID).Extract()
if err != nil {
t.Errorf("Unable to retrieve snapshot: %v", err)
}
name := "NewName"
description := ""
options := snapshots.UpdateOpts{
DisplayName: &name,
DisplayDescription: &description,
}
expectedSnapshot.Name = name
expectedSnapshot.Description = description
_, err = snapshots.Update(client, snapshot.ID, options).Extract()
if err != nil {
t.Errorf("Unable to update snapshot: %v", err)
}
updatedSnapshot, err := snapshots.Get(client, snapshot.ID).Extract()
if err != nil {
t.Errorf("Unable to retrieve snapshot: %v", err)
}
tools.PrintResource(t, snapshot)
th.CheckDeepEquals(t, expectedSnapshot, updatedSnapshot)
}
func TestSnapshotListDetail(t *testing.T) {
client, err := clients.NewSharedFileSystemV2Client()
if err != nil {
t.Fatalf("Unable to create a shared file system client: %v", err)
}
share, err := CreateShare(t, client)
if err != nil {
t.Fatalf("Unable to create a share: %v", err)
}
defer DeleteShare(t, client, share)
snapshot, err := CreateSnapshot(t, client, share.ID)
if err != nil {
t.Fatalf("Unable to create a snapshot: %v", err)
}
defer DeleteSnapshot(t, client, snapshot)
ss, err := ListSnapshots(t, client)
if err != nil {
t.Fatalf("Unable to list snapshots: %v", err)
}
for i := range ss {
tools.PrintResource(t, &ss[i])
}
}
|