blob: 3ba7a5e478eba8325bc22a5a458de2c1f85a6bea [file] [log] [blame]
Jamie Hannafordfac40db2015-02-09 17:27:08 +01001package instances
2
3import (
4 "testing"
5
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +01006 "github.com/rackspace/gophercloud"
Jamie Hannaford2e817322015-02-16 15:29:17 +01007 osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
Jamie Hannaford9fdda582015-02-10 12:15:43 +01008 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford2e817322015-02-16 15:29:17 +01009 osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
Jamie Hannafordfac40db2015-02-09 17:27:08 +010010 th "github.com/rackspace/gophercloud/testhelper"
11 fake "github.com/rackspace/gophercloud/testhelper/client"
12)
13
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010014var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f"
15
16var expectedInstance = &Instance{
17 Created: "2014-02-13T21:47:13",
18 Updated: "2014-02-13T21:47:13",
19 Datastore: Datastore{Type: "mysql", Version: "5.6"},
20 Flavor: os.Flavor{
21 ID: "1",
22 Links: []gophercloud.Link{
23 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
24 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
25 },
26 },
27 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
28 ID: instanceID,
29 Links: []gophercloud.Link{
30 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
31 },
32 Name: "json_rack_instance",
33 Status: "BUILD",
34 Volume: os.Volume{Size: 2},
35}
36
Jamie Hannafordfac40db2015-02-09 17:27:08 +010037func TestCreate(t *testing.T) {
38 th.SetupHTTP()
39 defer th.TeardownHTTP()
40
41 HandleCreateInstanceSuccessfully(t)
42
43 opts := CreateOpts{
44 Name: "json_rack_instance",
45 FlavorRef: "1",
Jamie Hannaford2e817322015-02-16 15:29:17 +010046 Databases: osDBs.BatchCreateOpts{
47 osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
48 osDBs.CreateOpts{Name: "nextround"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010049 },
Jamie Hannaford2e817322015-02-16 15:29:17 +010050 Users: osUsers.BatchCreateOpts{
51 osUsers.CreateOpts{
Jamie Hannafordfac40db2015-02-09 17:27:08 +010052 Name: "demouser",
53 Password: "demopassword",
Jamie Hannaford2e817322015-02-16 15:29:17 +010054 Databases: osDBs.BatchCreateOpts{
55 osDBs.CreateOpts{Name: "sampledb"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010056 },
57 },
58 },
59 Size: 2,
60 RestorePoint: "1234567890",
61 }
62
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010063 instance, err := Create(fake.ServiceClient(), opts).Extract()
64
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010065 th.AssertNoErr(t, err)
66 th.AssertDeepEquals(t, expectedInstance, instance)
67}
68
69func TestGet(t *testing.T) {
70 th.SetupHTTP()
71 defer th.TeardownHTTP()
72
73 HandleGetInstanceSuccessfully(t, instanceID)
74
75 instance, err := Get(fake.ServiceClient(), instanceID).Extract()
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010076
77 th.AssertNoErr(t, err)
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010078 th.AssertDeepEquals(t, expectedInstance, instance)
Jamie Hannafordfac40db2015-02-09 17:27:08 +010079}
Jamie Hannaford1232e042015-02-10 13:36:32 +010080
81func TestDeleteInstance(t *testing.T) {
82 th.SetupHTTP()
83 defer th.TeardownHTTP()
84
85 os.HandleDeleteInstanceSuccessfully(t, instanceID)
86
87 res := Delete(fake.ServiceClient(), instanceID)
88 th.AssertNoErr(t, res.Err)
89}
Jamie Hannafordebcac552015-02-10 13:58:56 +010090
91func TestEnableRootUser(t *testing.T) {
92 th.SetupHTTP()
93 defer th.TeardownHTTP()
94
95 os.HandleEnableRootUserSuccessfully(t, instanceID)
96
Jamie Hannaford2e817322015-02-16 15:29:17 +010097 expected := &osUsers.User{Name: "root", Password: "secretsecret"}
Jamie Hannafordebcac552015-02-10 13:58:56 +010098
99 user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract()
100 th.AssertNoErr(t, err)
101 th.AssertDeepEquals(t, expected, user)
102}
Jamie Hannaforde6390d42015-02-10 15:59:28 +0100103
104func TestRestartService(t *testing.T) {
105 th.SetupHTTP()
106 defer th.TeardownHTTP()
107
108 os.HandleRestartSuccessfully(t, instanceID)
109
110 res := RestartService(fake.ServiceClient(), instanceID)
111
112 th.AssertNoErr(t, res.Err)
113}
114
115func TestResizeInstance(t *testing.T) {
116 th.SetupHTTP()
117 defer th.TeardownHTTP()
118
119 os.HandleResizeInstanceSuccessfully(t, instanceID)
120
121 res := ResizeInstance(fake.ServiceClient(), instanceID, "2")
122
123 th.AssertNoErr(t, res.Err)
124}
125
126func TestResizeVolume(t *testing.T) {
127 th.SetupHTTP()
128 defer th.TeardownHTTP()
129
130 os.HandleResizeVolSuccessfully(t, instanceID)
131
132 res := ResizeVolume(fake.ServiceClient(), instanceID, 4)
133
134 th.AssertNoErr(t, res.Err)
135}