blob: c818fe1721fa1c3d74f3d199402848a4f1bad6ea [file] [log] [blame]
Jamie Hannaford3c1796b2015-02-12 14:21:33 +01001package users
2
3import (
4 "testing"
5
6 db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
7 os "github.com/rackspace/gophercloud/openstack/db/v1/users"
8 "github.com/rackspace/gophercloud/pagination"
9 th "github.com/rackspace/gophercloud/testhelper"
10 fake "github.com/rackspace/gophercloud/testhelper/client"
11)
12
13const instanceID = "{instanceID}"
14
15func TestCreate(t *testing.T) {
16 th.SetupHTTP()
17 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010018 os.HandleCreate(t)
Jamie Hannaford3c1796b2015-02-12 14:21:33 +010019
20 opts := os.BatchCreateOpts{
21 os.CreateOpts{
22 Databases: db.BatchCreateOpts{
23 db.CreateOpts{Name: "databaseA"},
24 },
25 Name: "dbuser3",
26 Password: "secretsecret",
27 },
28 os.CreateOpts{
29 Databases: db.BatchCreateOpts{
30 db.CreateOpts{Name: "databaseB"},
31 db.CreateOpts{Name: "databaseC"},
32 },
33 Name: "dbuser4",
34 Password: "secretsecret",
35 },
36 }
37
38 res := Create(fake.ServiceClient(), instanceID, opts)
39 th.AssertNoErr(t, res.Err)
40}
41
42func TestUserList(t *testing.T) {
43 th.SetupHTTP()
44 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010045 os.HandleList(t)
Jamie Hannaford3c1796b2015-02-12 14:21:33 +010046
47 expectedUsers := []os.User{
48 os.User{
49 Databases: []db.Database{
50 db.Database{Name: "databaseA"},
51 },
52 Name: "dbuser3",
53 },
54 os.User{
55 Databases: []db.Database{
56 db.Database{Name: "databaseB"},
57 db.Database{Name: "databaseC"},
58 },
59 Name: "dbuser4",
60 },
61 }
62
63 pages := 0
64 err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
65 pages++
66
67 actual, err := os.ExtractUsers(page)
68 if err != nil {
69 return false, err
70 }
71
72 th.CheckDeepEquals(t, expectedUsers, actual)
73
74 return true, nil
75 })
76
77 th.AssertNoErr(t, err)
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010078 th.AssertEquals(t, 1, pages)
Jamie Hannaford3c1796b2015-02-12 14:21:33 +010079}
80
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010081func TestDelete(t *testing.T) {
Jamie Hannaford3c1796b2015-02-12 14:21:33 +010082 th.SetupHTTP()
83 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010084 os.HandleDelete(t)
Jamie Hannaford3c1796b2015-02-12 14:21:33 +010085
86 res := Delete(fake.ServiceClient(), instanceID, "{userName}")
87 th.AssertNoErr(t, res.Err)
88}