blob: faa5bba2f89920cac31cab430464d645b594310b [file] [log] [blame]
Jamie Hannaford4e7c7202014-10-30 11:46:21 +01001// +build acceptance identity
2
3package v2
4
5import (
Jamie Hannaford4e7c7202014-10-30 11:46:21 +01006 "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/identity/v2/users"
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010011)
12
Joe Topjian918f5732016-08-15 08:47:08 -060013func TestUsersList(t *testing.T) {
14 client, err := clients.NewIdentityV2AdminClient()
15 if err != nil {
16 t.Fatalf("Unable to obtain an identity client: %v", err)
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010017 }
18
Joe Topjian918f5732016-08-15 08:47:08 -060019 allPages, err := users.List(client).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to list users: %v", err)
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010022 }
23
Joe Topjian918f5732016-08-15 08:47:08 -060024 allUsers, err := users.ExtractUsers(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract users: %v", err)
27 }
28
29 for _, user := range allUsers {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, user)
Joe Topjian918f5732016-08-15 08:47:08 -060031 }
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010032}
33
Joe Topjian918f5732016-08-15 08:47:08 -060034func TestUsersCreateUpdateDelete(t *testing.T) {
35 client, err := clients.NewIdentityV2AdminClient()
36 if err != nil {
37 t.Fatalf("Unable to obtain an identity client: %v", err)
38 }
39
40 tenant, err := FindTenant(t, client)
41 if err != nil {
42 t.Fatalf("Unable to get a tenant: %v", err)
43 }
44
45 user, err := CreateUser(t, client, tenant)
46 if err != nil {
47 t.Fatalf("Unable to create a user: %v", err)
48 }
49 defer DeleteUser(t, client, user)
50
Joe Topjian66a046c2017-01-19 22:07:26 -070051 tools.PrintResource(t, user)
Joe Topjian918f5732016-08-15 08:47:08 -060052
53 newUser, err := UpdateUser(t, client, user)
54 if err != nil {
55 t.Fatalf("Unable to update user: %v", err)
56 }
57
Joe Topjian66a046c2017-01-19 22:07:26 -070058 tools.PrintResource(t, newUser)
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010059}