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 | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 7 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 12 | var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f" |
| 13 | |
| 14 | var expectedInstance = &Instance{ |
| 15 | Created: "2014-02-13T21:47:13", |
| 16 | Updated: "2014-02-13T21:47:13", |
| 17 | Datastore: Datastore{Type: "mysql", Version: "5.6"}, |
| 18 | Flavor: os.Flavor{ |
| 19 | ID: "1", |
| 20 | Links: []gophercloud.Link{ |
| 21 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 22 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"}, |
| 23 | }, |
| 24 | }, |
| 25 | Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com", |
| 26 | ID: instanceID, |
| 27 | Links: []gophercloud.Link{ |
| 28 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 29 | }, |
| 30 | Name: "json_rack_instance", |
| 31 | Status: "BUILD", |
| 32 | Volume: os.Volume{Size: 2}, |
| 33 | } |
| 34 | |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 35 | func TestCreate(t *testing.T) { |
| 36 | th.SetupHTTP() |
| 37 | defer th.TeardownHTTP() |
| 38 | |
| 39 | HandleCreateInstanceSuccessfully(t) |
| 40 | |
| 41 | opts := CreateOpts{ |
| 42 | Name: "json_rack_instance", |
| 43 | FlavorRef: "1", |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 44 | Databases: os.DatabasesOpts{ |
| 45 | os.DatabaseOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 46 | os.DatabaseOpts{Name: "nextround"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 47 | }, |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 48 | Users: os.UsersOpts{ |
| 49 | os.UserOpts{ |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 50 | Name: "demouser", |
| 51 | Password: "demopassword", |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 52 | Databases: os.DatabasesOpts{ |
| 53 | os.DatabaseOpts{Name: "sampledb"}, |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 54 | }, |
| 55 | }, |
| 56 | }, |
| 57 | Size: 2, |
| 58 | RestorePoint: "1234567890", |
| 59 | } |
| 60 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 61 | instance, err := Create(fake.ServiceClient(), opts).Extract() |
| 62 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 63 | th.AssertNoErr(t, err) |
| 64 | th.AssertDeepEquals(t, expectedInstance, instance) |
| 65 | } |
| 66 | |
| 67 | func TestGet(t *testing.T) { |
| 68 | th.SetupHTTP() |
| 69 | defer th.TeardownHTTP() |
| 70 | |
| 71 | HandleGetInstanceSuccessfully(t, instanceID) |
| 72 | |
| 73 | instance, err := Get(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 74 | |
| 75 | th.AssertNoErr(t, err) |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 76 | th.AssertDeepEquals(t, expectedInstance, instance) |
Jamie Hannaford | fac40db | 2015-02-09 17:27:08 +0100 | [diff] [blame] | 77 | } |
Jamie Hannaford | 1232e04 | 2015-02-10 13:36:32 +0100 | [diff] [blame] | 78 | |
| 79 | func TestDeleteInstance(t *testing.T) { |
| 80 | th.SetupHTTP() |
| 81 | defer th.TeardownHTTP() |
| 82 | |
| 83 | os.HandleDeleteInstanceSuccessfully(t, instanceID) |
| 84 | |
| 85 | res := Delete(fake.ServiceClient(), instanceID) |
| 86 | th.AssertNoErr(t, res.Err) |
| 87 | } |