Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 6 | osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases" |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 7 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 8 | osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | fake "github.com/rackspace/gophercloud/testhelper/client" |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/testhelper/fixture" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 12 | ) |
| 13 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 14 | var ( |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 15 | _rootURL = "/instances" |
| 16 | resURL = "/instances/" + instanceID |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 17 | ) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 18 | |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 19 | func TestCreate(t *testing.T) { |
| 20 | th.SetupHTTP() |
| 21 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 22 | fixture.SetupHandler(t, _rootURL, "POST", createReq, createResp, 200) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 23 | |
| 24 | opts := CreateOpts{ |
| 25 | Name: "json_rack_instance", |
| 26 | FlavorRef: "1", |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 27 | Databases: osDBs.BatchCreateOpts{ |
| 28 | osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 29 | osDBs.CreateOpts{Name: "nextround"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 30 | }, |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 31 | Users: osUsers.BatchCreateOpts{ |
| 32 | osUsers.CreateOpts{ |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 33 | Name: "demouser", |
| 34 | Password: "demopassword", |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 35 | Databases: osDBs.BatchCreateOpts{ |
| 36 | osDBs.CreateOpts{Name: "sampledb"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 37 | }, |
| 38 | }, |
| 39 | }, |
| 40 | Size: 2, |
| 41 | RestorePoint: "1234567890", |
| 42 | } |
| 43 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 44 | instance, err := Create(fake.ServiceClient(), opts).Extract() |
| 45 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 46 | th.AssertNoErr(t, err) |
| 47 | th.AssertDeepEquals(t, expectedInstance, instance) |
| 48 | } |
| 49 | |
| 50 | func TestGet(t *testing.T) { |
| 51 | th.SetupHTTP() |
| 52 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 53 | fixture.SetupHandler(t, resURL, "GET", "", getResp, 200) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 54 | |
| 55 | instance, err := Get(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 56 | |
| 57 | th.AssertNoErr(t, err) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 58 | th.AssertDeepEquals(t, expectedInstance, instance) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 59 | } |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 60 | |
| 61 | func TestDeleteInstance(t *testing.T) { |
| 62 | th.SetupHTTP() |
| 63 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 64 | os.HandleDelete(t) |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 65 | |
| 66 | res := Delete(fake.ServiceClient(), instanceID) |
| 67 | th.AssertNoErr(t, res.Err) |
| 68 | } |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 69 | |
| 70 | func TestEnableRootUser(t *testing.T) { |
| 71 | th.SetupHTTP() |
| 72 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 73 | os.HandleEnableRoot(t) |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 74 | |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 75 | expected := &osUsers.User{Name: "root", Password: "secretsecret"} |
Jamie Hannaford | ebcac55 | 2015-02-10 13:58:56 +0100 | [diff] [blame] | 76 | |
| 77 | user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract() |
| 78 | th.AssertNoErr(t, err) |
| 79 | th.AssertDeepEquals(t, expected, user) |
| 80 | } |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 81 | |
| 82 | func TestRestartService(t *testing.T) { |
| 83 | th.SetupHTTP() |
| 84 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 85 | os.HandleRestart(t) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 86 | |
| 87 | res := RestartService(fake.ServiceClient(), instanceID) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 88 | th.AssertNoErr(t, res.Err) |
| 89 | } |
| 90 | |
| 91 | func TestResizeInstance(t *testing.T) { |
| 92 | th.SetupHTTP() |
| 93 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 94 | os.HandleResize(t) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 95 | |
| 96 | res := ResizeInstance(fake.ServiceClient(), instanceID, "2") |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 97 | th.AssertNoErr(t, res.Err) |
| 98 | } |
| 99 | |
| 100 | func TestResizeVolume(t *testing.T) { |
| 101 | th.SetupHTTP() |
| 102 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 103 | os.HandleResizeVol(t) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 104 | |
| 105 | res := ResizeVolume(fake.ServiceClient(), instanceID, 4) |
Jamie Hannaford | e6390d4 | 2015-02-10 15:59:28 +0100 | [diff] [blame] | 106 | th.AssertNoErr(t, res.Err) |
| 107 | } |