blob: e902dfea8cbdeb27b3dad832285ffee777bd5c40 [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 Hannaford9fdda582015-02-10 12:15:43 +01007 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannafordfac40db2015-02-09 17:27:08 +01008 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010012var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f"
13
14var expectedInstance = &Instance{
15 Created: "2014-02-13T21:47:13",
16 Updated: "2014-02-13T21:47:13",
17 Datastore: Datastore{Type: "mysql", Version: "5.6"},
18 Flavor: os.Flavor{
19 ID: "1",
20 Links: []gophercloud.Link{
21 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
22 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
23 },
24 },
25 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
26 ID: instanceID,
27 Links: []gophercloud.Link{
28 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
29 },
30 Name: "json_rack_instance",
31 Status: "BUILD",
32 Volume: os.Volume{Size: 2},
33}
34
Jamie Hannafordfac40db2015-02-09 17:27:08 +010035func TestCreate(t *testing.T) {
36 th.SetupHTTP()
37 defer th.TeardownHTTP()
38
39 HandleCreateInstanceSuccessfully(t)
40
41 opts := CreateOpts{
42 Name: "json_rack_instance",
43 FlavorRef: "1",
Jamie Hannaford9fdda582015-02-10 12:15:43 +010044 Databases: os.DatabasesOpts{
45 os.DatabaseOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
46 os.DatabaseOpts{Name: "nextround"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010047 },
Jamie Hannaford9fdda582015-02-10 12:15:43 +010048 Users: os.UsersOpts{
49 os.UserOpts{
Jamie Hannafordfac40db2015-02-09 17:27:08 +010050 Name: "demouser",
51 Password: "demopassword",
Jamie Hannaford9fdda582015-02-10 12:15:43 +010052 Databases: os.DatabasesOpts{
53 os.DatabaseOpts{Name: "sampledb"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010054 },
55 },
56 },
57 Size: 2,
58 RestorePoint: "1234567890",
59 }
60
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010061 instance, err := Create(fake.ServiceClient(), opts).Extract()
62
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010063 th.AssertNoErr(t, err)
64 th.AssertDeepEquals(t, expectedInstance, instance)
65}
66
67func TestGet(t *testing.T) {
68 th.SetupHTTP()
69 defer th.TeardownHTTP()
70
71 HandleGetInstanceSuccessfully(t, instanceID)
72
73 instance, err := Get(fake.ServiceClient(), instanceID).Extract()
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010074
75 th.AssertNoErr(t, err)
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010076 th.AssertDeepEquals(t, expectedInstance, instance)
Jamie Hannafordfac40db2015-02-09 17:27:08 +010077}
Jamie Hannaford1232e042015-02-10 13:36:32 +010078
79func TestDeleteInstance(t *testing.T) {
80 th.SetupHTTP()
81 defer th.TeardownHTTP()
82
83 os.HandleDeleteInstanceSuccessfully(t, instanceID)
84
85 res := Delete(fake.ServiceClient(), instanceID)
86 th.AssertNoErr(t, res.Err)
87}
Jamie Hannafordebcac552015-02-10 13:58:56 +010088
89func TestEnableRootUser(t *testing.T) {
90 th.SetupHTTP()
91 defer th.TeardownHTTP()
92
93 os.HandleEnableRootUserSuccessfully(t, instanceID)
94
95 expected := &os.User{Name: "root", Password: "secretsecret"}
96
97 user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract()
98 th.AssertNoErr(t, err)
99 th.AssertDeepEquals(t, expected, user)
100}