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 | |
| 9 | "github.com/rackspace/gophercloud/openstack" |
| 10 | "github.com/rackspace/gophercloud/openstack/utils" |
| 11 | ) |
| 12 | |
| 13 | func TestAuthenticatedClient(t *testing.T) { |
| 14 | // Obtain credentials from the environment. |
| 15 | ao, err := utils.AuthOptions() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Unable to acquire credentials: %v", err) |
| 18 | } |
| 19 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame] | 20 | // Trim out unused fields. |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame^] | 21 | ao.TenantID, ao.TenantName, ao.Username = "", "", "" |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame] | 22 | |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 23 | client, err := openstack.AuthenticatedClient(ao) |
| 24 | if err != nil { |
| 25 | t.Fatalf("Unable to authenticate: %v", err) |
| 26 | } |
| 27 | |
| 28 | if client.TokenID == "" { |
| 29 | t.Errorf("No token ID assigned to the client") |
| 30 | } |
| 31 | |
| 32 | t.Logf("Client successfully acquired a token: %v", client.TokenID) |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame^] | 33 | |
| 34 | // Find the storage service in the service catalog. |
| 35 | storage, err := openstack.NewStorageV1(client, os.Getenv("OS_REGION_NAME")) |
| 36 | if err != nil { |
| 37 | t.Errorf("Unable to locate a storage service: %v", err) |
| 38 | } else { |
| 39 | t.Logf("Located a storage service at endpoint: [%s]", storage.Endpoint) |
| 40 | } |
Ash Wilson | 33c85f4 | 2014-09-02 14:09:14 -0400 | [diff] [blame] | 41 | } |