blob: 053e2acd18abdb478514823557a47b82e780c896 [file] [log] [blame]
Ash Wilsonc25ae602014-09-02 14:41:12 -04001// +build acceptance
2
Ash Wilson33c85f42014-09-02 14:09:14 -04003package openstack
4
5import (
Ash Wilson1cd3e692014-09-09 11:01:47 -04006 "os"
Ash Wilson33c85f42014-09-02 14:09:14 -04007 "testing"
8
9 "github.com/rackspace/gophercloud/openstack"
10 "github.com/rackspace/gophercloud/openstack/utils"
11)
12
13func 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 Wilson9d9fb102014-09-03 11:26:31 -040020 // Trim out unused fields.
Ash Wilson1cd3e692014-09-09 11:01:47 -040021 ao.TenantID, ao.TenantName, ao.Username = "", "", ""
Ash Wilson9d9fb102014-09-03 11:26:31 -040022
Ash Wilson33c85f42014-09-02 14:09:14 -040023 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 Wilson1cd3e692014-09-09 11:01:47 -040033
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 Wilson33c85f42014-09-02 14:09:14 -040041}