blob: 13b38f83abd1de6d77e29c8165c7d608b22296cd [file] [log] [blame]
Ash Wilson42156912014-09-02 14:08:22 -04001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Joe Topjian918f5732016-08-15 08:47:08 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Jon Perritt27249f42016-02-18 10:35:59 -06009 "github.com/gophercloud/gophercloud/openstack"
Joe Topjian918f5732016-08-15 08:47:08 -060010 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
Ash Wilson42156912014-09-02 14:08:22 -040011)
12
13func TestGetToken(t *testing.T) {
Joe Topjian918f5732016-08-15 08:47:08 -060014 client, err := clients.NewIdentityV3UnauthenticatedClient()
15 if err != nil {
16 t.Fatalf("Unable to obtain an identity client: %v")
17 }
18
Jamie Hannaford390555a2014-10-22 17:04:03 +020019 ao, err := openstack.AuthOptionsFromEnv()
Ash Wilson42156912014-09-02 14:08:22 -040020 if err != nil {
Joe Topjian918f5732016-08-15 08:47:08 -060021 t.Fatalf("Unable to obtain environment auth options: %v", err)
Ash Wilson42156912014-09-02 14:08:22 -040022 }
23
Joe Topjian918f5732016-08-15 08:47:08 -060024 authOptions := tokens.AuthOptions{
25 Username: ao.Username,
26 Password: ao.Password,
27 DomainName: "default",
Ash Wilson7083d022014-09-09 14:10:43 -040028 }
Ash Wilson42156912014-09-02 14:08:22 -040029
Joe Topjian918f5732016-08-15 08:47:08 -060030 token, err := tokens.Create(client, &authOptions).Extract()
Ash Wilson42156912014-09-02 14:08:22 -040031 if err != nil {
32 t.Fatalf("Unable to get token: %v", err)
33 }
34
Joe Topjian918f5732016-08-15 08:47:08 -060035 PrintToken(t, token)
Ash Wilson42156912014-09-02 14:08:22 -040036}