blob: d5f9ea62b003feb03504b369f4124e0221869348 [file] [log] [blame]
Ash Wilson42156912014-09-02 14:08:22 -04001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Ash Wilson9d9fb102014-09-03 11:26:31 -04008 "github.com/rackspace/gophercloud/openstack"
9 tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
Ash Wilson42156912014-09-02 14:08:22 -040010 "github.com/rackspace/gophercloud/openstack/utils"
11)
12
13func TestGetToken(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 Wilson7083d022014-09-09 14:10:43 -040020 // Trim out unused fields. Skip if we don't have a UserID.
Ash Wilsondd7188d2014-09-05 14:02:42 -040021 ao.Username, ao.TenantID, ao.TenantName = "", "", ""
Ash Wilson7083d022014-09-09 14:10:43 -040022 if ao.UserID == "" {
23 t.Logf("Skipping identity v3 tests because no OS_USERID is present.")
24 return
25 }
Ash Wilson42156912014-09-02 14:08:22 -040026
Ash Wilson9d9fb102014-09-03 11:26:31 -040027 // Create an unauthenticated client.
28 provider, err := openstack.NewClient(ao.IdentityEndpoint)
29 if err != nil {
30 t.Fatalf("Unable to instantiate client: %v", err)
31 }
32
33 // Create a service client.
34 service := openstack.NewIdentityV3(provider)
35
36 // Use the service to create a token.
37 result, err := tokens3.Create(service, ao, nil)
Ash Wilson42156912014-09-02 14:08:22 -040038 if err != nil {
39 t.Fatalf("Unable to get token: %v", err)
40 }
41
Ash Wilson9d9fb102014-09-03 11:26:31 -040042 token, err := result.TokenID()
43 if err != nil {
44 t.Fatalf("Unable to extract token from response: %v", err)
45 }
46
47 t.Logf("Acquired token: %s", token)
Ash Wilson42156912014-09-02 14:08:22 -040048}