blob: 5711f6334af575852114f3729f5fe8aa0de5dadf [file] [log] [blame]
Jamie Hannafordaf4570f2015-02-12 13:33:25 +01001package users
2
3import (
4 "testing"
5
6 db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010010)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010011
12func TestCreate(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010015 HandleCreate(t)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010016
17 opts := BatchCreateOpts{
18 CreateOpts{
19 Databases: db.BatchCreateOpts{
20 db.CreateOpts{Name: "databaseA"},
21 },
22 Name: "dbuser3",
23 Password: "secretsecret",
24 },
25 CreateOpts{
26 Databases: db.BatchCreateOpts{
27 db.CreateOpts{Name: "databaseB"},
28 db.CreateOpts{Name: "databaseC"},
29 },
30 Name: "dbuser4",
31 Password: "secretsecret",
32 },
33 }
34
35 res := Create(fake.ServiceClient(), instanceID, opts)
36 th.AssertNoErr(t, res.Err)
37}
38
39func TestUserList(t *testing.T) {
40 th.SetupHTTP()
41 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010042 HandleList(t)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010043
44 expectedUsers := []User{
45 User{
46 Databases: []db.Database{
47 db.Database{Name: "databaseA"},
48 },
49 Name: "dbuser3",
50 },
51 User{
52 Databases: []db.Database{
53 db.Database{Name: "databaseB"},
54 db.Database{Name: "databaseC"},
55 },
56 Name: "dbuser4",
57 },
58 }
59
60 pages := 0
61 err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
62 pages++
63
64 actual, err := ExtractUsers(page)
65 if err != nil {
66 return false, err
67 }
68
69 th.CheckDeepEquals(t, expectedUsers, actual)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010070 return true, nil
71 })
72
73 th.AssertNoErr(t, err)
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010074 th.AssertEquals(t, 1, pages)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010075}
76
Jamie Hannaford4a170282015-02-18 14:16:57 +010077func TestDelete(t *testing.T) {
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010078 th.SetupHTTP()
79 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010080 HandleDelete(t)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010081
Jamie Hannaford4a170282015-02-18 14:16:57 +010082 res := Delete(fake.ServiceClient(), instanceID, "{userName}")
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010083 th.AssertNoErr(t, res.Err)
84}