blob: 4342ade03ccf9319367cd0cfd803e4ceedff6f0d [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)
11
12func TestGetToken(t *testing.T) {
13 // Obtain credentials from the environment.
Jamie Hannaford390555a2014-10-22 17:04:03 +020014 ao, err := openstack.AuthOptionsFromEnv()
Ash Wilson42156912014-09-02 14:08:22 -040015 if err != nil {
16 t.Fatalf("Unable to acquire credentials: %v", err)
17 }
18
Ash Wilson7083d022014-09-09 14:10:43 -040019 // Trim out unused fields. Skip if we don't have a UserID.
Ash Wilsondd7188d2014-09-05 14:02:42 -040020 ao.Username, ao.TenantID, ao.TenantName = "", "", ""
Ash Wilson7083d022014-09-09 14:10:43 -040021 if ao.UserID == "" {
22 t.Logf("Skipping identity v3 tests because no OS_USERID is present.")
23 return
24 }
Ash Wilson42156912014-09-02 14:08:22 -040025
Ash Wilson9d9fb102014-09-03 11:26:31 -040026 // Create an unauthenticated client.
27 provider, err := openstack.NewClient(ao.IdentityEndpoint)
28 if err != nil {
29 t.Fatalf("Unable to instantiate client: %v", err)
30 }
31
32 // Create a service client.
33 service := openstack.NewIdentityV3(provider)
34
35 // Use the service to create a token.
Ash Wilson15f5b122014-10-02 09:54:54 -040036 token, err := tokens3.Create(service, ao, nil).Extract()
Ash Wilson42156912014-09-02 14:08:22 -040037 if err != nil {
38 t.Fatalf("Unable to get token: %v", err)
39 }
40
Ash Wilson15f5b122014-10-02 09:54:54 -040041 t.Logf("Acquired token: %s", token.ID)
Ash Wilson42156912014-09-02 14:08:22 -040042}