blob: e94ce39374224a98c3e46e0c3a6a462a7b7b1fde [file] [log] [blame]
Jamie Hannafordfac40db2015-02-09 17:27:08 +01001package instances
2
3import (
4 "testing"
5
Jamie Hannaford2e817322015-02-16 15:29:17 +01006 osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
Jamie Hannaford9fdda582015-02-10 12:15:43 +01007 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford2e817322015-02-16 15:29:17 +01008 osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
Jamie Hannafordfac40db2015-02-09 17:27:08 +01009 th "github.com/rackspace/gophercloud/testhelper"
10 fake "github.com/rackspace/gophercloud/testhelper/client"
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010011 "github.com/rackspace/gophercloud/testhelper/fixture"
Jamie Hannafordfac40db2015-02-09 17:27:08 +010012)
13
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010014var (
Jamie Hannaford72749162015-10-14 12:14:32 +020015 _rootURL = "/instances"
16 resURL = "/instances/" + instanceID
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010017)
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010018
Jamie Hannafordfac40db2015-02-09 17:27:08 +010019func TestCreate(t *testing.T) {
20 th.SetupHTTP()
21 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010022 fixture.SetupHandler(t, _rootURL, "POST", createReq, createResp, 200)
Jamie Hannafordfac40db2015-02-09 17:27:08 +010023
24 opts := CreateOpts{
25 Name: "json_rack_instance",
26 FlavorRef: "1",
Jamie Hannaford2e817322015-02-16 15:29:17 +010027 Databases: osDBs.BatchCreateOpts{
28 osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
29 osDBs.CreateOpts{Name: "nextround"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010030 },
Jamie Hannaford2e817322015-02-16 15:29:17 +010031 Users: osUsers.BatchCreateOpts{
32 osUsers.CreateOpts{
Jamie Hannafordfac40db2015-02-09 17:27:08 +010033 Name: "demouser",
34 Password: "demopassword",
Jamie Hannaford2e817322015-02-16 15:29:17 +010035 Databases: osDBs.BatchCreateOpts{
36 osDBs.CreateOpts{Name: "sampledb"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010037 },
38 },
39 },
40 Size: 2,
41 RestorePoint: "1234567890",
42 }
43
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010044 instance, err := Create(fake.ServiceClient(), opts).Extract()
45
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010046 th.AssertNoErr(t, err)
47 th.AssertDeepEquals(t, expectedInstance, instance)
48}
49
50func TestGet(t *testing.T) {
51 th.SetupHTTP()
52 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010053 fixture.SetupHandler(t, resURL, "GET", "", getResp, 200)
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010054
55 instance, err := Get(fake.ServiceClient(), instanceID).Extract()
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010056
57 th.AssertNoErr(t, err)
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010058 th.AssertDeepEquals(t, expectedInstance, instance)
Jamie Hannafordfac40db2015-02-09 17:27:08 +010059}
Jamie Hannaford1232e042015-02-10 13:36:32 +010060
61func TestDeleteInstance(t *testing.T) {
62 th.SetupHTTP()
63 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010064 os.HandleDelete(t)
Jamie Hannaford1232e042015-02-10 13:36:32 +010065
66 res := Delete(fake.ServiceClient(), instanceID)
67 th.AssertNoErr(t, res.Err)
68}
Jamie Hannafordebcac552015-02-10 13:58:56 +010069
70func TestEnableRootUser(t *testing.T) {
71 th.SetupHTTP()
72 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010073 os.HandleEnableRoot(t)
Jamie Hannafordebcac552015-02-10 13:58:56 +010074
Jamie Hannaford2e817322015-02-16 15:29:17 +010075 expected := &osUsers.User{Name: "root", Password: "secretsecret"}
Jamie Hannafordebcac552015-02-10 13:58:56 +010076
77 user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract()
78 th.AssertNoErr(t, err)
79 th.AssertDeepEquals(t, expected, user)
80}
Jamie Hannaforde6390d42015-02-10 15:59:28 +010081
82func TestRestartService(t *testing.T) {
83 th.SetupHTTP()
84 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010085 os.HandleRestart(t)
Jamie Hannaforde6390d42015-02-10 15:59:28 +010086
87 res := RestartService(fake.ServiceClient(), instanceID)
Jamie Hannaforde6390d42015-02-10 15:59:28 +010088 th.AssertNoErr(t, res.Err)
89}
90
91func TestResizeInstance(t *testing.T) {
92 th.SetupHTTP()
93 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010094 os.HandleResize(t)
Jamie Hannaforde6390d42015-02-10 15:59:28 +010095
96 res := ResizeInstance(fake.ServiceClient(), instanceID, "2")
Jamie Hannaforde6390d42015-02-10 15:59:28 +010097 th.AssertNoErr(t, res.Err)
98}
99
100func TestResizeVolume(t *testing.T) {
101 th.SetupHTTP()
102 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100103 os.HandleResizeVol(t)
Jamie Hannaforde6390d42015-02-10 15:59:28 +0100104
105 res := ResizeVolume(fake.ServiceClient(), instanceID, 4)
Jamie Hannaforde6390d42015-02-10 15:59:28 +0100106 th.AssertNoErr(t, res.Err)
107}