Ash Wilson | c25ae60 | 2014-09-02 14:41:12 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 3 | package openstack |
| 4 | |
| 5 | import ( |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 6 | "os" |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 7 | "testing" |
| 8 | |
Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud" |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/openstack" |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestAuthenticatedClient(t *testing.T) { |
| 14 | // Obtain credentials from the environment. |
Jamie Hannaford | 390555a | 2014-10-22 17:04:03 +0200 | [diff] [blame] | 15 | ao, err := openstack.AuthOptionsFromEnv() |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 16 | if err != nil { |
| 17 | t.Fatalf("Unable to acquire credentials: %v", err) |
| 18 | } |
| 19 | |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 20 | client, err := openstack.AuthenticatedClient(ao) |
| 21 | if err != nil { |
| 22 | t.Fatalf("Unable to authenticate: %v", err) |
| 23 | } |
| 24 | |
| 25 | if client.TokenID == "" { |
| 26 | t.Errorf("No token ID assigned to the client") |
| 27 | } |
| 28 | |
| 29 | t.Logf("Client successfully acquired a token: %v", client.TokenID) |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 30 | |
| 31 | // Find the storage service in the service catalog. |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 32 | storage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{ |
Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 33 | Region: os.Getenv("OS_REGION_NAME"), |
| 34 | }) |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 35 | if err != nil { |
| 36 | t.Errorf("Unable to locate a storage service: %v", err) |
| 37 | } else { |
| 38 | t.Logf("Located a storage service at endpoint: [%s]", storage.Endpoint) |
| 39 | } |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 40 | } |