github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/blockstorage/noauth/snapshots_test.go (about)

     1  //go:build acceptance || blockstorage
     2  // +build acceptance blockstorage
     3  
     4  package noauth
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/gophercloud/gophercloud/internal/acceptance/clients"
    10  	"github.com/gophercloud/gophercloud/internal/acceptance/tools"
    11  	"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots"
    12  )
    13  
    14  func TestSnapshotsList(t *testing.T) {
    15  	client, err := clients.NewBlockStorageV3NoAuthClient()
    16  	if err != nil {
    17  		t.Fatalf("Unable to create a blockstorage client: %v", err)
    18  	}
    19  
    20  	allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages()
    21  	if err != nil {
    22  		t.Fatalf("Unable to retrieve snapshots: %v", err)
    23  	}
    24  
    25  	allSnapshots, err := snapshots.ExtractSnapshots(allPages)
    26  	if err != nil {
    27  		t.Fatalf("Unable to extract snapshots: %v", err)
    28  	}
    29  
    30  	for _, snapshot := range allSnapshots {
    31  		tools.PrintResource(t, snapshot)
    32  	}
    33  }
    34  
    35  func TestSnapshotsCreateDelete(t *testing.T) {
    36  	client, err := clients.NewBlockStorageV3NoAuthClient()
    37  	if err != nil {
    38  		t.Fatalf("Unable to create a blockstorage client: %v", err)
    39  	}
    40  
    41  	volume, err := CreateVolume(t, client)
    42  	if err != nil {
    43  		t.Fatalf("Unable to create volume: %v", err)
    44  	}
    45  	defer DeleteVolume(t, client, volume)
    46  
    47  	snapshot, err := CreateSnapshot(t, client, volume)
    48  	if err != nil {
    49  		t.Fatalf("Unable to create snapshot: %v", err)
    50  	}
    51  	defer DeleteSnapshot(t, client, snapshot)
    52  
    53  	newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract()
    54  	if err != nil {
    55  		t.Errorf("Unable to retrieve snapshot: %v", err)
    56  	}
    57  
    58  	tools.PrintResource(t, newSnapshot)
    59  }