blob: e0f90d92bafbecab877fd6da098fefadd23f932a [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"
Joe Topjian66a046c2017-01-19 22:07:26 -07009 "github.com/gophercloud/gophercloud/acceptance/tools"
Jon Perritt27249f42016-02-18 10:35:59 -060010 "github.com/gophercloud/gophercloud/openstack"
Joe Topjian918f5732016-08-15 08:47:08 -060011 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
Ash Wilson42156912014-09-02 14:08:22 -040012)
13
14func TestGetToken(t *testing.T) {
Joe Topjian918f5732016-08-15 08:47:08 -060015 client, err := clients.NewIdentityV3UnauthenticatedClient()
16 if err != nil {
17 t.Fatalf("Unable to obtain an identity client: %v")
18 }
19
Jamie Hannaford390555a2014-10-22 17:04:03 +020020 ao, err := openstack.AuthOptionsFromEnv()
Ash Wilson42156912014-09-02 14:08:22 -040021 if err != nil {
Joe Topjian918f5732016-08-15 08:47:08 -060022 t.Fatalf("Unable to obtain environment auth options: %v", err)
Ash Wilson42156912014-09-02 14:08:22 -040023 }
24
Joe Topjian918f5732016-08-15 08:47:08 -060025 authOptions := tokens.AuthOptions{
26 Username: ao.Username,
27 Password: ao.Password,
28 DomainName: "default",
Ash Wilson7083d022014-09-09 14:10:43 -040029 }
Ash Wilson42156912014-09-02 14:08:22 -040030
Joe Topjian918f5732016-08-15 08:47:08 -060031 token, err := tokens.Create(client, &authOptions).Extract()
Ash Wilson42156912014-09-02 14:08:22 -040032 if err != nil {
33 t.Fatalf("Unable to get token: %v", err)
34 }
35
Joe Topjian66a046c2017-01-19 22:07:26 -070036 tools.PrintResource(t, token)
Ash Wilson42156912014-09-02 14:08:22 -040037}