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 | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 10 | "github.com/rackspace/gophercloud/rackspace/db/v1/datastores" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 13 | ) |
| 14 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 15 | var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f" |
| 16 | |
| 17 | var expectedInstance = &Instance{ |
| 18 | Created: "2014-02-13T21:47:13", |
| 19 | Updated: "2014-02-13T21:47:13", |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 20 | Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"}, |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 21 | 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 Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 38 | func 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 Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 47 | Databases: osDBs.BatchCreateOpts{ |
| 48 | osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 49 | osDBs.CreateOpts{Name: "nextround"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 50 | }, |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 51 | Users: osUsers.BatchCreateOpts{ |
| 52 | osUsers.CreateOpts{ |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 53 | Name: "demouser", |
| 54 | Password: "demopassword", |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 55 | Databases: osDBs.BatchCreateOpts{ |
| 56 | osDBs.CreateOpts{Name: "sampledb"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 57 | }, |
| 58 | }, |
| 59 | }, |
| 60 | Size: 2, |
| 61 | RestorePoint: "1234567890", |
| 62 | } |
| 63 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 64 | instance, err := Create(fake.ServiceClient(), opts).Extract() |
| 65 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 66 | th.AssertNoErr(t, err) |
| 67 | th.AssertDeepEquals(t, expectedInstance, instance) |
| 68 | } |
| 69 | |
| 70 | func 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 Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 77 | |
| 78 | th.AssertNoErr(t, err) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 79 | th.AssertDeepEquals(t, expectedInstance, instance) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 80 | } |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 81 | |
| 82 | func 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 Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 91 | |
| 92 | func TestEnableRootUser(t *testing.T) { |
| 93 | th.SetupHTTP() |
| 94 | defer th.TeardownHTTP() |
| 95 | |
| 96 | os.HandleEnableRootUserSuccessfully(t, instanceID) |
| 97 | |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 98 | expected := &osUsers.User{Name: "root", Password: "secretsecret"} |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 99 | |
| 100 | user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract() |
| 101 | th.AssertNoErr(t, err) |
| 102 | th.AssertDeepEquals(t, expected, user) |
| 103 | } |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 104 | |
| 105 | func 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 | |
| 116 | func 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 | |
| 127 | func 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 | } |