blob: 6e88819d80e8ba816def872aa70c6e412aa158b2 [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"
Ash Wilson33c85f42014-09-02 14:09:14 -040011)
12
13func TestAuthenticatedClient(t *testing.T) {
14 // Obtain credentials from the environment.
Jamie Hannaford390555a2014-10-22 17:04:03 +020015 ao, err := openstack.AuthOptionsFromEnv()
Ash Wilson33c85f42014-09-02 14:09:14 -040016 if err != nil {
17 t.Fatalf("Unable to acquire credentials: %v", err)
18 }
19
Ash Wilson33c85f42014-09-02 14:09:14 -040020 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 Wilson1cd3e692014-09-09 11:01:47 -040030
31 // Find the storage service in the service catalog.
Jon Perritt2a7797d2014-10-21 15:08:43 -050032 storage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{
Jon Perritt509fbb62014-09-10 13:29:56 -050033 Region: os.Getenv("OS_REGION_NAME"),
34 })
Ash Wilson1cd3e692014-09-09 11:01:47 -040035 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 Wilson33c85f42014-09-02 14:09:14 -040040}