Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame^] | 5 | "testing" |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 6 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame^] | 8 | "github.com/rackspace/gophercloud/testhelper/fixture" |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 9 | ) |
| 10 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 11 | const instance = ` |
| 12 | { |
| 13 | "created": "2014-02-13T21:47:13", |
| 14 | "datastore": { |
| 15 | "type": "mysql", |
| 16 | "version": "5.6" |
| 17 | }, |
| 18 | "flavor": { |
| 19 | "id": "1", |
| 20 | "links": [ |
| 21 | { |
| 22 | "href": "https://my-openstack.com/v1.0/1234/flavors/1", |
| 23 | "rel": "self" |
| 24 | }, |
| 25 | { |
| 26 | "href": "https://my-openstack.com/v1.0/1234/flavors/1", |
| 27 | "rel": "bookmark" |
| 28 | } |
| 29 | ] |
| 30 | }, |
| 31 | "links": [ |
| 32 | { |
| 33 | "href": "https://my-openstack.com/v1.0/1234/instances/1", |
| 34 | "rel": "self" |
| 35 | } |
| 36 | ], |
| 37 | "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com", |
| 38 | "id": "{instanceID}", |
| 39 | "name": "json_rack_instance", |
| 40 | "status": "BUILD", |
| 41 | "updated": "2014-02-13T21:47:13", |
| 42 | "volume": { |
| 43 | "size": 2 |
| 44 | } |
| 45 | } |
| 46 | ` |
| 47 | |
| 48 | var createReq = ` |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 49 | { |
| 50 | "instance": { |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 51 | "databases": [ |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 52 | { |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 53 | "character_set": "utf8", |
| 54 | "collate": "utf8_general_ci", |
| 55 | "name": "sampledb" |
| 56 | }, |
| 57 | { |
| 58 | "name": "nextround" |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 59 | } |
| 60 | ], |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 61 | "flavorRef": "1", |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 62 | "name": "json_rack_instance", |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 63 | "users": [ |
| 64 | { |
| 65 | "databases": [ |
| 66 | { |
| 67 | "name": "sampledb" |
| 68 | } |
| 69 | ], |
| 70 | "name": "demouser", |
| 71 | "password": "demopassword" |
| 72 | } |
| 73 | ], |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 74 | "volume": { |
| 75 | "size": 2 |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | ` |
| 80 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 81 | var ( |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame^] | 82 | instanceID = "{instanceID}" |
| 83 | rootURL = "/instances" |
| 84 | resURL = rootURL + "/" + instanceID |
| 85 | uRootURL = resURL + "/root" |
| 86 | aURL = resURL + "/action" |
| 87 | ) |
| 88 | |
| 89 | var ( |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 90 | restartReq = `{"restart": true}` |
| 91 | resizeReq = `{"resize": {"flavorRef": "2"}}` |
| 92 | resizeVolReq = `{"resize": {"volume": {"size": 4}}}` |
| 93 | ) |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 94 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 95 | var ( |
| 96 | createResp = fmt.Sprintf(`{"instance": %s}`, instance) |
| 97 | listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance) |
| 98 | getInstanceResp = createResp |
| 99 | enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}` |
| 100 | isUserEnabledResp = `{"rootEnabled":true}` |
| 101 | ) |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 102 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 103 | var expectedInstance = Instance{ |
| 104 | Created: "2014-02-13T21:47:13", |
| 105 | Updated: "2014-02-13T21:47:13", |
| 106 | Flavor: Flavor{ |
| 107 | ID: "1", |
| 108 | Links: []gophercloud.Link{ |
| 109 | gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 110 | gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "bookmark"}, |
| 111 | }, |
| 112 | }, |
| 113 | Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com", |
| 114 | ID: instanceID, |
| 115 | Links: []gophercloud.Link{ |
| 116 | gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/instances/1", Rel: "self"}, |
| 117 | }, |
| 118 | Name: "json_rack_instance", |
| 119 | Status: "BUILD", |
| 120 | Volume: Volume{Size: 2}, |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 121 | } |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame^] | 122 | |
| 123 | func HandleCreate(t *testing.T) { |
| 124 | fixture.SetupHandler(t, rootURL, "POST", createReq, createResp, 200) |
| 125 | } |
| 126 | |
| 127 | func HandleList(t *testing.T) { |
| 128 | fixture.SetupHandler(t, rootURL, "GET", "", listInstancesResp, 200) |
| 129 | } |
| 130 | |
| 131 | func HandleGet(t *testing.T) { |
| 132 | fixture.SetupHandler(t, resURL, "GET", "", getInstanceResp, 200) |
| 133 | } |
| 134 | |
| 135 | func HandleDelete(t *testing.T) { |
| 136 | fixture.SetupHandler(t, resURL, "DELETE", "", "", 202) |
| 137 | } |
| 138 | |
| 139 | func HandleEnableRoot(t *testing.T) { |
| 140 | fixture.SetupHandler(t, uRootURL, "POST", "", enableUserResp, 200) |
| 141 | } |
| 142 | |
| 143 | func HandleIsRootEnabled(t *testing.T) { |
| 144 | fixture.SetupHandler(t, uRootURL, "GET", "", isUserEnabledResp, 200) |
| 145 | } |
| 146 | |
| 147 | func HandleRestart(t *testing.T) { |
| 148 | fixture.SetupHandler(t, aURL, "POST", restartReq, "", 202) |
| 149 | } |
| 150 | |
| 151 | func HandleResize(t *testing.T) { |
| 152 | fixture.SetupHandler(t, aURL, "POST", resizeReq, "", 202) |
| 153 | } |
| 154 | |
| 155 | func HandleResizeVol(t *testing.T) { |
| 156 | fixture.SetupHandler(t, aURL, "POST", resizeVolReq, "", 202) |
| 157 | } |