Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v3 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack" |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestGetToken(t *testing.T) { |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 14 | client, err := clients.NewIdentityV3UnauthenticatedClient() |
| 15 | if err != nil { |
| 16 | t.Fatalf("Unable to obtain an identity client: %v") |
| 17 | } |
| 18 | |
Jamie Hannaford | 390555a | 2014-10-22 17:04:03 +0200 | [diff] [blame] | 19 | ao, err := openstack.AuthOptionsFromEnv() |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 20 | if err != nil { |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 21 | t.Fatalf("Unable to obtain environment auth options: %v", err) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 22 | } |
| 23 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 24 | authOptions := tokens.AuthOptions{ |
| 25 | Username: ao.Username, |
| 26 | Password: ao.Password, |
| 27 | DomainName: "default", |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 28 | } |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 29 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 30 | token, err := tokens.Create(client, &authOptions).Extract() |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 31 | if err != nil { |
| 32 | t.Fatalf("Unable to get token: %v", err) |
| 33 | } |
| 34 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 35 | PrintToken(t, token) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 36 | } |