| // +build acceptance |
| |
| package openstack |
| |
| import ( |
| "fmt" |
| blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1" |
| "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" |
| "github.com/rackspace/gophercloud/openstack/identity" |
| "github.com/rackspace/gophercloud/openstack/utils" |
| "os" |
| "testing" |
| ) |
| |
| func getClient() (*blockstorage.Client, error) { |
| ao, err := utils.AuthOptions() |
| if err != nil { |
| return nil, err |
| } |
| |
| r, err := identity.Authenticate(ao) |
| if err != nil { |
| return nil, err |
| } |
| |
| sc, err := identity.GetServiceCatalog(r) |
| if err != nil { |
| return nil, err |
| } |
| |
| ces, err := sc.CatalogEntries() |
| if err != nil { |
| return nil, err |
| } |
| |
| var eps []identity.Endpoint |
| for _, ce := range ces { |
| if ce.Type == "volume" { |
| eps = ce.Endpoints |
| } |
| } |
| |
| region := os.Getenv("OS_REGION_NAME") |
| rep := "" |
| for _, ep := range eps { |
| if ep.Region == region { |
| rep = ep.PublicURL |
| } |
| } |
| |
| client := blockstorage.NewClient(rep, r, ao) |
| |
| return client, nil |
| |
| } |
| |
| func TestVolumes(t *testing.T) { |
| client, err := getClient() |
| if err != nil { |
| t.Error(err) |
| return |
| } |
| nv, err := volumes.Create(client, volumes.CreateOpts{ |
| "size": 1, |
| "display_name": "test-volume", |
| }) |
| if err != nil { |
| t.Error(err) |
| return |
| } |
| |
| defer func() { |
| err = volumes.Delete(client, volumes.DeleteOpts{ |
| "id": nv.Id, |
| }) |
| }() |
| |
| gv, err := volumes.Get(client, volumes.GetOpts{ |
| "id": nv.Id, |
| }) |
| if err != nil { |
| t.Error(err) |
| return |
| } |
| fmt.Printf("%+v\n", gv) |
| } |