github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/blockstorage/noauth/volumes_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/volumes"
    12  )
    13  
    14  func TestVolumesList(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 := volumes.List(client, volumes.ListOpts{}).AllPages()
    21  	if err != nil {
    22  		t.Fatalf("Unable to retrieve volumes: %v", err)
    23  	}
    24  
    25  	allVolumes, err := volumes.ExtractVolumes(allPages)
    26  	if err != nil {
    27  		t.Fatalf("Unable to extract volumes: %v", err)
    28  	}
    29  
    30  	for _, volume := range allVolumes {
    31  		tools.PrintResource(t, volume)
    32  	}
    33  }
    34  
    35  func TestVolumesCreateDestroy(t *testing.T) {
    36  	client, err := clients.NewBlockStorageV3NoAuthClient()
    37  	if err != nil {
    38  		t.Fatalf("Unable to create 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  	newVolume, err := volumes.Get(client, volume.ID).Extract()
    48  	if err != nil {
    49  		t.Errorf("Unable to retrieve volume: %v", err)
    50  	}
    51  
    52  	tools.PrintResource(t, newVolume)
    53  }