blob: 52c0cf57805de765b3d0c5d51f4458cbb481c610 [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
Jon Perritt509fbb62014-09-10 13:29:56 -05009 "github.com/rackspace/gophercloud"
Ash Wilson33c85f42014-09-02 14:09:14 -040010 "github.com/rackspace/gophercloud/openstack"
11 "github.com/rackspace/gophercloud/openstack/utils"
12)
13
14func TestAuthenticatedClient(t *testing.T) {
15 // Obtain credentials from the environment.
16 ao, err := utils.AuthOptions()
17 if err != nil {
18 t.Fatalf("Unable to acquire credentials: %v", err)
19 }
20
Ash Wilson33c85f42014-09-02 14:09:14 -040021 client, err := openstack.AuthenticatedClient(ao)
22 if err != nil {
23 t.Fatalf("Unable to authenticate: %v", err)
24 }
25
26 if client.TokenID == "" {
27 t.Errorf("No token ID assigned to the client")
28 }
29
30 t.Logf("Client successfully acquired a token: %v", client.TokenID)
Ash Wilson1cd3e692014-09-09 11:01:47 -040031
32 // Find the storage service in the service catalog.
Jon Perritt509fbb62014-09-10 13:29:56 -050033 storage, err := openstack.NewStorageV1(client, gophercloud.EndpointOpts{
34 Region: os.Getenv("OS_REGION_NAME"),
35 })
Ash Wilson1cd3e692014-09-09 11:01:47 -040036 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}