blob: 03dd47a78acec567df2f4777f4bbca5e61e5af00 [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
12func TestCreate(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15
16 HandleCreateInstanceSuccessfully(t)
17
18 opts := CreateOpts{
19 Name: "json_rack_instance",
20 FlavorRef: "1",
Jamie Hannaford9fdda582015-02-10 12:15:43 +010021 Databases: os.DatabasesOpts{
22 os.DatabaseOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
23 os.DatabaseOpts{Name: "nextround"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010024 },
Jamie Hannaford9fdda582015-02-10 12:15:43 +010025 Users: os.UsersOpts{
26 os.UserOpts{
Jamie Hannafordfac40db2015-02-09 17:27:08 +010027 Name: "demouser",
28 Password: "demopassword",
Jamie Hannaford9fdda582015-02-10 12:15:43 +010029 Databases: os.DatabasesOpts{
30 os.DatabaseOpts{Name: "sampledb"},
Jamie Hannafordfac40db2015-02-09 17:27:08 +010031 },
32 },
33 },
34 Size: 2,
35 RestorePoint: "1234567890",
36 }
37
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010038 instance, err := Create(fake.ServiceClient(), opts).Extract()
39
40 expected := &Instance{
41 Created: "2014-02-13T21:47:13",
42 Updated: "2014-02-13T21:47:13",
43 Datastore: Datastore{Type: "mysql", Version: "5.6"},
Jamie Hannaford9fdda582015-02-10 12:15:43 +010044 Flavor: os.Flavor{
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010045 ID: "1",
46 Links: []gophercloud.Link{
47 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
48 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
49 },
50 },
51 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
52 ID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
53 Links: []gophercloud.Link{
54 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
55 },
56 Name: "json_rack_instance",
57 Status: "BUILD",
Jamie Hannaford9fdda582015-02-10 12:15:43 +010058 Volume: os.Volume{Size: 2},
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010059 }
60
61 th.AssertNoErr(t, err)
62 th.AssertDeepEquals(t, expected, instance)
Jamie Hannafordfac40db2015-02-09 17:27:08 +010063}