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