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 | 8803f83 | 2015-02-23 10:44:55 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/openstack/db/v1/flavors" |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 9 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 10 | osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users" |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/rackspace/db/v1/datastores" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | fake "github.com/rackspace/gophercloud/testhelper/client" |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 14 | "github.com/rackspace/gophercloud/testhelper/fixture" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 15 | ) |
| 16 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 17 | var ( |
| 18 | instanceID = "{instanceID}" |
| 19 | _rootURL = "/instances" |
| 20 | resURL = "/instances/" + instanceID |
| 21 | ) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 22 | |
| 23 | var expectedInstance = &Instance{ |
| 24 | Created: "2014-02-13T21:47:13", |
| 25 | Updated: "2014-02-13T21:47:13", |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 26 | Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"}, |
Jamie Hannaford | 8803f83 | 2015-02-23 10:44:55 +0100 | [diff] [blame] | 27 | Flavor: flavors.Flavor{ |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 28 | ID: "1", |
| 29 | Links: []gophercloud.Link{ |
| 30 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 31 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"}, |
| 32 | }, |
| 33 | }, |
| 34 | Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com", |
| 35 | ID: instanceID, |
| 36 | Links: []gophercloud.Link{ |
| 37 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 38 | }, |
| 39 | Name: "json_rack_instance", |
| 40 | Status: "BUILD", |
| 41 | Volume: os.Volume{Size: 2}, |
| 42 | } |
| 43 | |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 44 | func TestCreate(t *testing.T) { |
| 45 | th.SetupHTTP() |
| 46 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 47 | fixture.SetupHandler(t, _rootURL, "POST", createReq, createResp, 200) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 48 | |
| 49 | opts := CreateOpts{ |
| 50 | Name: "json_rack_instance", |
| 51 | FlavorRef: "1", |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 52 | Databases: osDBs.BatchCreateOpts{ |
| 53 | osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 54 | osDBs.CreateOpts{Name: "nextround"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 55 | }, |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 56 | Users: osUsers.BatchCreateOpts{ |
| 57 | osUsers.CreateOpts{ |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 58 | Name: "demouser", |
| 59 | Password: "demopassword", |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 60 | Databases: osDBs.BatchCreateOpts{ |
| 61 | osDBs.CreateOpts{Name: "sampledb"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | Size: 2, |
| 66 | RestorePoint: "1234567890", |
| 67 | } |
| 68 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 69 | instance, err := Create(fake.ServiceClient(), opts).Extract() |
| 70 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 71 | th.AssertNoErr(t, err) |
| 72 | th.AssertDeepEquals(t, expectedInstance, instance) |
| 73 | } |
| 74 | |
| 75 | func TestGet(t *testing.T) { |
| 76 | th.SetupHTTP() |
| 77 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 78 | fixture.SetupHandler(t, resURL, "GET", "", getResp, 200) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 79 | |
| 80 | instance, err := Get(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 81 | |
| 82 | th.AssertNoErr(t, err) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 83 | th.AssertDeepEquals(t, expectedInstance, instance) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 84 | } |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 85 | |
| 86 | func TestDeleteInstance(t *testing.T) { |
| 87 | th.SetupHTTP() |
| 88 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 89 | os.HandleDelete(t) |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 90 | |
| 91 | res := Delete(fake.ServiceClient(), instanceID) |
| 92 | th.AssertNoErr(t, res.Err) |
| 93 | } |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 94 | |
| 95 | func TestEnableRootUser(t *testing.T) { |
| 96 | th.SetupHTTP() |
| 97 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 98 | os.HandleEnableRoot(t) |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 99 | |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 100 | expected := &osUsers.User{Name: "root", Password: "secretsecret"} |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 101 | |
| 102 | user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract() |
| 103 | th.AssertNoErr(t, err) |
| 104 | th.AssertDeepEquals(t, expected, user) |
| 105 | } |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 106 | |
| 107 | func TestRestartService(t *testing.T) { |
| 108 | th.SetupHTTP() |
| 109 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 110 | os.HandleRestart(t) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 111 | |
| 112 | res := RestartService(fake.ServiceClient(), instanceID) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 113 | th.AssertNoErr(t, res.Err) |
| 114 | } |
| 115 | |
| 116 | func TestResizeInstance(t *testing.T) { |
| 117 | th.SetupHTTP() |
| 118 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 119 | os.HandleResize(t) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 120 | |
| 121 | res := ResizeInstance(fake.ServiceClient(), instanceID, "2") |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 122 | th.AssertNoErr(t, res.Err) |
| 123 | } |
| 124 | |
| 125 | func TestResizeVolume(t *testing.T) { |
| 126 | th.SetupHTTP() |
| 127 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 128 | os.HandleResizeVol(t) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 129 | |
| 130 | res := ResizeVolume(fake.ServiceClient(), instanceID, 4) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 131 | th.AssertNoErr(t, res.Err) |
| 132 | } |