blob: 5d409f3f044cc889c093e17267b755e0bd0aa16a [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 Wilson9d9fb102014-09-03 11:26:31 -040020 // Trim out unused fields.
21 ao.TenantID, ao.TenantName = "", ""
Ash Wilson42156912014-09-02 14:08:22 -040022
Ash Wilson9d9fb102014-09-03 11:26:31 -040023 // Create an unauthenticated client.
24 provider, err := openstack.NewClient(ao.IdentityEndpoint)
25 if err != nil {
26 t.Fatalf("Unable to instantiate client: %v", err)
27 }
28
29 // Create a service client.
30 service := openstack.NewIdentityV3(provider)
31
32 // Use the service to create a token.
33 result, err := tokens3.Create(service, ao, nil)
Ash Wilson42156912014-09-02 14:08:22 -040034 if err != nil {
35 t.Fatalf("Unable to get token: %v", err)
36 }
37
Ash Wilson9d9fb102014-09-03 11:26:31 -040038 token, err := result.TokenID()
39 if err != nil {
40 t.Fatalf("Unable to extract token from response: %v", err)
41 }
42
43 t.Logf("Acquired token: %s", token)
Ash Wilson42156912014-09-02 14:08:22 -040044}