github.com/leeclow-ops/gophercloud@v1.2.1/acceptance/openstack/blockstorage/v3/snapshots_test.go (about) 1 //go:build acceptance || blockstorage 2 // +build acceptance blockstorage 3 4 package v3 5 6 import ( 7 "testing" 8 9 "github.com/leeclow-ops/gophercloud/acceptance/clients" 10 "github.com/leeclow-ops/gophercloud/acceptance/tools" 11 "github.com/leeclow-ops/gophercloud/openstack/blockstorage/v3/snapshots" 12 "github.com/leeclow-ops/gophercloud/pagination" 13 th "github.com/leeclow-ops/gophercloud/testhelper" 14 ) 15 16 func TestSnapshots(t *testing.T) { 17 clients.RequireLong(t) 18 19 client, err := clients.NewBlockStorageV3Client() 20 th.AssertNoErr(t, err) 21 22 volume1, err := CreateVolume(t, client) 23 th.AssertNoErr(t, err) 24 defer DeleteVolume(t, client, volume1) 25 26 snapshot1, err := CreateSnapshot(t, client, volume1) 27 th.AssertNoErr(t, err) 28 defer DeleteSnapshot(t, client, snapshot1) 29 30 // Update snapshot 31 updatedSnapshotName := tools.RandomString("ACPTTEST", 16) 32 updatedSnapshotDescription := tools.RandomString("ACPTTEST", 16) 33 updateOpts := snapshots.UpdateOpts{ 34 Name: &updatedSnapshotName, 35 Description: &updatedSnapshotDescription, 36 } 37 t.Logf("Attempting to update snapshot: %s", updatedSnapshotName) 38 updatedSnapshot, err := snapshots.Update(client, snapshot1.ID, updateOpts).Extract() 39 th.AssertNoErr(t, err) 40 41 tools.PrintResource(t, updatedSnapshot) 42 th.AssertEquals(t, updatedSnapshot.Name, updatedSnapshotName) 43 th.AssertEquals(t, updatedSnapshot.Description, updatedSnapshotDescription) 44 45 volume2, err := CreateVolume(t, client) 46 th.AssertNoErr(t, err) 47 defer DeleteVolume(t, client, volume2) 48 49 snapshot2, err := CreateSnapshot(t, client, volume2) 50 th.AssertNoErr(t, err) 51 defer DeleteSnapshot(t, client, snapshot2) 52 53 listOpts := snapshots.ListOpts{ 54 Limit: 1, 55 } 56 57 err = snapshots.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) { 58 actual, err := snapshots.ExtractSnapshots(page) 59 th.AssertNoErr(t, err) 60 th.AssertEquals(t, 1, len(actual)) 61 62 var found bool 63 for _, v := range actual { 64 if v.ID == snapshot1.ID || v.ID == snapshot2.ID { 65 found = true 66 } 67 } 68 69 th.AssertEquals(t, found, true) 70 71 return true, nil 72 }) 73 74 th.AssertNoErr(t, err) 75 }