Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame^] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 9 | ) |
| 10 | |
| 11 | func TestCreate(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
| 14 | |
| 15 | HandleCreateInstanceSuccessfully(t) |
| 16 | |
| 17 | opts := CreateOpts{ |
| 18 | Name: "json_rack_instance", |
| 19 | FlavorRef: "1", |
| 20 | Databases: DatabasesOpts{ |
| 21 | DatabaseOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 22 | DatabaseOpts{Name: "nextround"}, |
| 23 | }, |
| 24 | Users: UsersOpts{ |
| 25 | UserOpts{ |
| 26 | Name: "demouser", |
| 27 | Password: "demopassword", |
| 28 | Databases: DatabasesOpts{ |
| 29 | DatabaseOpts{Name: "sampledb"}, |
| 30 | }, |
| 31 | }, |
| 32 | }, |
| 33 | Size: 2, |
| 34 | } |
| 35 | |
| 36 | instance, err := Create(fake.ServiceClient(), opts).Extract() |
| 37 | |
| 38 | expected := &Instance{ |
| 39 | Created: "2014-02-13T21:47:13", |
| 40 | Updated: "2014-02-13T21:47:13", |
| 41 | Flavor: Flavor{ |
| 42 | ID: "1", |
| 43 | Links: []gophercloud.Link{ |
| 44 | gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 45 | gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "bookmark"}, |
| 46 | }, |
| 47 | }, |
| 48 | Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com", |
| 49 | ID: "d4603f69-ec7e-4e9b-803f-600b9205576f", |
| 50 | Links: []gophercloud.Link{ |
| 51 | gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/instances/1", Rel: "self"}, |
| 52 | }, |
| 53 | Name: "json_rack_instance", |
| 54 | Status: "BUILD", |
| 55 | Volume: Volume{Size: 2}, |
| 56 | } |
| 57 | |
| 58 | th.AssertNoErr(t, err) |
| 59 | th.AssertDeepEquals(t, expected, instance) |
| 60 | } |