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

     1  //go:build acceptance || blockstorage
     2  // +build acceptance blockstorage
     3  
     4  package v1
     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/v1/snapshots"
    12  )
    13  
    14  func TestSnapshotsList(t *testing.T) {
    15  	clients.SkipReleasesAbove(t, "stable/icehouse")
    16  	client, err := clients.NewBlockStorageV1Client()
    17  	if err != nil {
    18  		t.Fatalf("Unable to create a blockstorage client: %v", err)
    19  	}
    20  
    21  	allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages()
    22  	if err != nil {
    23  		t.Fatalf("Unable to retrieve snapshots: %v", err)
    24  	}
    25  
    26  	allSnapshots, err := snapshots.ExtractSnapshots(allPages)
    27  	if err != nil {
    28  		t.Fatalf("Unable to extract snapshots: %v", err)
    29  	}
    30  
    31  	for _, snapshot := range allSnapshots {
    32  		tools.PrintResource(t, snapshot)
    33  	}
    34  }
    35  
    36  func TestSnapshotsCreateDelete(t *testing.T) {
    37  	clients.SkipReleasesAbove(t, "stable/icehouse")
    38  	client, err := clients.NewBlockStorageV1Client()
    39  	if err != nil {
    40  		t.Fatalf("Unable to create a blockstorage client: %v", err)
    41  	}
    42  
    43  	volume, err := CreateVolume(t, client)
    44  	if err != nil {
    45  		t.Fatalf("Unable to create volume: %v", err)
    46  	}
    47  	defer DeleteVolume(t, client, volume)
    48  
    49  	snapshot, err := CreateSnapshot(t, client, volume)
    50  	if err != nil {
    51  		t.Fatalf("Unable to create snapshot: %v", err)
    52  	}
    53  	defer DeleteSnapshotshot(t, client, snapshot)
    54  
    55  	newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract()
    56  	if err != nil {
    57  		t.Errorf("Unable to retrieve snapshot: %v", err)
    58  	}
    59  
    60  	tools.PrintResource(t, newSnapshot)
    61  }