blob: 5c6bfd9b67419d2aff6ed4167d86010904c20777 [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"
Jon Perritt27249f42016-02-18 10:35:59 -06009 "github.com/gophercloud/gophercloud/openstack/identity/v2/users"
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010010)
11
Joe Topjian918f5732016-08-15 08:47:08 -060012func TestUsersList(t *testing.T) {
13 client, err := clients.NewIdentityV2AdminClient()
14 if err != nil {
15 t.Fatalf("Unable to obtain an identity client: %v", err)
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010016 }
17
Joe Topjian918f5732016-08-15 08:47:08 -060018 allPages, err := users.List(client).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to list users: %v", err)
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010021 }
22
Joe Topjian918f5732016-08-15 08:47:08 -060023 allUsers, err := users.ExtractUsers(allPages)
24 if err != nil {
25 t.Fatalf("Unable to extract users: %v", err)
26 }
27
28 for _, user := range allUsers {
29 PrintUser(t, &user)
30 }
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010031}
32
Joe Topjian918f5732016-08-15 08:47:08 -060033func TestUsersCreateUpdateDelete(t *testing.T) {
34 client, err := clients.NewIdentityV2AdminClient()
35 if err != nil {
36 t.Fatalf("Unable to obtain an identity client: %v", err)
37 }
38
39 tenant, err := FindTenant(t, client)
40 if err != nil {
41 t.Fatalf("Unable to get a tenant: %v", err)
42 }
43
44 user, err := CreateUser(t, client, tenant)
45 if err != nil {
46 t.Fatalf("Unable to create a user: %v", err)
47 }
48 defer DeleteUser(t, client, user)
49
50 PrintUser(t, user)
51
52 newUser, err := UpdateUser(t, client, user)
53 if err != nil {
54 t.Fatalf("Unable to update user: %v", err)
55 }
56
57 PrintUser(t, newUser)
Jamie Hannaford4e7c7202014-10-30 11:46:21 +010058}