Jamie Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 1 | // +build acceptance identity |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Jamie Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 6 | "testing" |
| 7 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/identity/v2/users" |
Jamie Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 11 | ) |
| 12 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 13 | func 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 Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 17 | } |
| 18 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 19 | allPages, err := users.List(client).AllPages() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to list users: %v", err) |
Jamie Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 22 | } |
| 23 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 24 | 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 30 | tools.PrintResource(t, user) |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 31 | } |
Jamie Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 34 | func 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 51 | tools.PrintResource(t, user) |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 52 | |
| 53 | newUser, err := UpdateUser(t, client, user) |
| 54 | if err != nil { |
| 55 | t.Fatalf("Unable to update user: %v", err) |
| 56 | } |
| 57 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 58 | tools.PrintResource(t, newUser) |
Jamie Hannaford | 4e7c720 | 2014-10-30 11:46:21 +0100 | [diff] [blame] | 59 | } |