blob: d43b1e19846d1a28fe249e9eaf93e860bc882a28 [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 Hannaforda50d1352015-02-18 11:38:38 +010010 "github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
Jamie Hannafordfac40db2015-02-09 17:27:08 +010011 th "github.com/rackspace/gophercloud/testhelper"
12 fake "github.com/rackspace/gophercloud/testhelper/client"
13)
14
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010015var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f"
16
17var expectedInstance = &Instance{
18 Created: "2014-02-13T21:47:13",
19 Updated: "2014-02-13T21:47:13",
Jamie Hannaforda50d1352015-02-18 11:38:38 +010020 Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010021 Flavor: os.Flavor{
22 ID: "1",
23 Links: []gophercloud.Link{
24 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
25 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
26 },
27 },
28 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
29 ID: instanceID,
30 Links: []gophercloud.Link{
31 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
32 },
33 Name: "json_rack_instance",
34 Status: "BUILD",
35 Volume: os.Volume{Size: 2},
36}
37
Jamie Hannafordfac40db2015-02-09 17:27:08 +010038func TestCreate(t *testing.T) {
39 th.SetupHTTP()
40 defer th.TeardownHTTP()
41
42 HandleCreateInstanceSuccessfully(t)
43
44 opts := CreateOpts{
45 Name: "json_rack_instance",
46 FlavorRef: "1",
Jamie Hannaford2e817322015-02-16 15:29:17 +010047 Databases: osDBs.BatchCreateOpts{
48 osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
49 osDBs.CreateOpts{Name: "nextround"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010050 },
Jamie Hannaford2e817322015-02-16 15:29:17 +010051 Users: osUsers.BatchCreateOpts{
52 osUsers.CreateOpts{
Jamie Hannafordfac40db2015-02-09 17:27:08 +010053 Name: "demouser",
54 Password: "demopassword",
Jamie Hannaford2e817322015-02-16 15:29:17 +010055 Databases: osDBs.BatchCreateOpts{
56 osDBs.CreateOpts{Name: "sampledb"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010057 },
58 },
59 },
60 Size: 2,
61 RestorePoint: "1234567890",
62 }
63
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010064 instance, err := Create(fake.ServiceClient(), opts).Extract()
65
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010066 th.AssertNoErr(t, err)
67 th.AssertDeepEquals(t, expectedInstance, instance)
68}
69
70func TestGet(t *testing.T) {
71 th.SetupHTTP()
72 defer th.TeardownHTTP()
73
74 HandleGetInstanceSuccessfully(t, instanceID)
75
76 instance, err := Get(fake.ServiceClient(), instanceID).Extract()
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010077
78 th.AssertNoErr(t, err)
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010079 th.AssertDeepEquals(t, expectedInstance, instance)
Jamie Hannafordfac40db2015-02-09 17:27:08 +010080}
Jamie Hannaford1232e042015-02-10 13:36:32 +010081
82func TestDeleteInstance(t *testing.T) {
83 th.SetupHTTP()
84 defer th.TeardownHTTP()
85
86 os.HandleDeleteInstanceSuccessfully(t, instanceID)
87
88 res := Delete(fake.ServiceClient(), instanceID)
89 th.AssertNoErr(t, res.Err)
90}
Jamie Hannafordebcac552015-02-10 13:58:56 +010091
92func TestEnableRootUser(t *testing.T) {
93 th.SetupHTTP()
94 defer th.TeardownHTTP()
95
96 os.HandleEnableRootUserSuccessfully(t, instanceID)
97
Jamie Hannaford2e817322015-02-16 15:29:17 +010098 expected := &osUsers.User{Name: "root", Password: "secretsecret"}
Jamie Hannafordebcac552015-02-10 13:58:56 +010099
100 user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract()
101 th.AssertNoErr(t, err)
102 th.AssertDeepEquals(t, expected, user)
103}
Jamie Hannaforde6390d42015-02-10 15:59:28 +0100104
105func TestRestartService(t *testing.T) {
106 th.SetupHTTP()
107 defer th.TeardownHTTP()
108
109 os.HandleRestartSuccessfully(t, instanceID)
110
111 res := RestartService(fake.ServiceClient(), instanceID)
112
113 th.AssertNoErr(t, res.Err)
114}
115
116func TestResizeInstance(t *testing.T) {
117 th.SetupHTTP()
118 defer th.TeardownHTTP()
119
120 os.HandleResizeInstanceSuccessfully(t, instanceID)
121
122 res := ResizeInstance(fake.ServiceClient(), instanceID, "2")
123
124 th.AssertNoErr(t, res.Err)
125}
126
127func TestResizeVolume(t *testing.T) {
128 th.SetupHTTP()
129 defer th.TeardownHTTP()
130
131 os.HandleResizeVolSuccessfully(t, instanceID)
132
133 res := ResizeVolume(fake.ServiceClient(), instanceID, 4)
134
135 th.AssertNoErr(t, res.Err)
136}