Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 7 | osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases" |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 8 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 9 | osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 12 | ) |
| 13 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 14 | var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f" |
| 15 | |
| 16 | var 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 Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 37 | func 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 Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 46 | Databases: osDBs.BatchCreateOpts{ |
| 47 | osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 48 | osDBs.CreateOpts{Name: "nextround"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 49 | }, |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 50 | Users: osUsers.BatchCreateOpts{ |
| 51 | osUsers.CreateOpts{ |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 52 | Name: "demouser", |
| 53 | Password: "demopassword", |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 54 | Databases: osDBs.BatchCreateOpts{ |
| 55 | osDBs.CreateOpts{Name: "sampledb"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 56 | }, |
| 57 | }, |
| 58 | }, |
| 59 | Size: 2, |
| 60 | RestorePoint: "1234567890", |
| 61 | } |
| 62 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 63 | instance, err := Create(fake.ServiceClient(), opts).Extract() |
| 64 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 65 | th.AssertNoErr(t, err) |
| 66 | th.AssertDeepEquals(t, expectedInstance, instance) |
| 67 | } |
| 68 | |
| 69 | func 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 Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 76 | |
| 77 | th.AssertNoErr(t, err) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 78 | th.AssertDeepEquals(t, expectedInstance, instance) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 79 | } |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 80 | |
| 81 | func 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 Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 90 | |
| 91 | func TestEnableRootUser(t *testing.T) { |
| 92 | th.SetupHTTP() |
| 93 | defer th.TeardownHTTP() |
| 94 | |
| 95 | os.HandleEnableRootUserSuccessfully(t, instanceID) |
| 96 | |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 97 | expected := &osUsers.User{Name: "root", Password: "secretsecret"} |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 98 | |
| 99 | user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract() |
| 100 | th.AssertNoErr(t, err) |
| 101 | th.AssertDeepEquals(t, expected, user) |
| 102 | } |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 103 | |
| 104 | func 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 | |
| 115 | func 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 | |
| 126 | func 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 | } |