PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources/testing/fixtures.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 440 lines | 380 code | 31 blank | 29 comment | 1 complexity | e3ab3a570d95a74bb937b9e5ebf9f80d MD5 | raw file
  1. package testing
  2. import (
  3. "fmt"
  4. "net/http"
  5. "testing"
  6. "time"
  7. "github.com/gophercloud/gophercloud"
  8. "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources"
  9. th "github.com/gophercloud/gophercloud/testhelper"
  10. fake "github.com/gophercloud/gophercloud/testhelper/client"
  11. )
  12. // FindExpected represents the expected object from a Find request.
  13. var FindExpected = []stackresources.Resource{
  14. {
  15. Name: "hello_world",
  16. Links: []gophercloud.Link{
  17. {
  18. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  19. Rel: "self",
  20. },
  21. {
  22. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  23. Rel: "stack",
  24. },
  25. },
  26. LogicalID: "hello_world",
  27. StatusReason: "state changed",
  28. UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
  29. CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
  30. RequiredBy: []interface{}{},
  31. Status: "CREATE_IN_PROGRESS",
  32. PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
  33. Type: "OS::Nova::Server",
  34. Attributes: map[string]interface{}{"SXSW": "atx"},
  35. Description: "Some resource",
  36. },
  37. }
  38. // FindOutput represents the response body from a Find request.
  39. const FindOutput = `
  40. {
  41. "resources": [
  42. {
  43. "description": "Some resource",
  44. "attributes": {"SXSW": "atx"},
  45. "resource_name": "hello_world",
  46. "links": [
  47. {
  48. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  49. "rel": "self"
  50. },
  51. {
  52. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  53. "rel": "stack"
  54. }
  55. ],
  56. "logical_resource_id": "hello_world",
  57. "resource_status_reason": "state changed",
  58. "updated_time": "2015-02-05T21:33:11",
  59. "creation_time": "2015-02-05T21:33:10",
  60. "required_by": [],
  61. "resource_status": "CREATE_IN_PROGRESS",
  62. "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
  63. "resource_type": "OS::Nova::Server"
  64. }
  65. ]
  66. }`
  67. // HandleFindSuccessfully creates an HTTP handler at `/stacks/hello_world/resources`
  68. // on the test handler mux that responds with a `Find` response.
  69. func HandleFindSuccessfully(t *testing.T, output string) {
  70. th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) {
  71. th.TestMethod(t, r, "GET")
  72. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  73. th.TestHeader(t, r, "Accept", "application/json")
  74. w.Header().Set("Content-Type", "application/json")
  75. w.WriteHeader(http.StatusOK)
  76. fmt.Fprintf(w, output)
  77. })
  78. }
  79. // ListExpected represents the expected object from a List request.
  80. var ListExpected = []stackresources.Resource{
  81. {
  82. Name: "hello_world",
  83. Links: []gophercloud.Link{
  84. {
  85. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  86. Rel: "self",
  87. },
  88. {
  89. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  90. Rel: "stack",
  91. },
  92. },
  93. LogicalID: "hello_world",
  94. StatusReason: "state changed",
  95. UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
  96. CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
  97. RequiredBy: []interface{}{},
  98. Status: "CREATE_IN_PROGRESS",
  99. PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
  100. Type: "OS::Nova::Server",
  101. Attributes: map[string]interface{}{"SXSW": "atx"},
  102. Description: "Some resource",
  103. },
  104. }
  105. // ListOutput represents the response body from a List request.
  106. const ListOutput = `{
  107. "resources": [
  108. {
  109. "resource_name": "hello_world",
  110. "links": [
  111. {
  112. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  113. "rel": "self"
  114. },
  115. {
  116. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  117. "rel": "stack"
  118. }
  119. ],
  120. "logical_resource_id": "hello_world",
  121. "resource_status_reason": "state changed",
  122. "updated_time": "2015-02-05T21:33:11",
  123. "required_by": [],
  124. "resource_status": "CREATE_IN_PROGRESS",
  125. "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
  126. "creation_time": "2015-02-05T21:33:10",
  127. "resource_type": "OS::Nova::Server",
  128. "attributes": {"SXSW": "atx"},
  129. "description": "Some resource"
  130. }
  131. ]
  132. }`
  133. // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources`
  134. // on the test handler mux that responds with a `List` response.
  135. func HandleListSuccessfully(t *testing.T, output string) {
  136. th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources", func(w http.ResponseWriter, r *http.Request) {
  137. th.TestMethod(t, r, "GET")
  138. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  139. th.TestHeader(t, r, "Accept", "application/json")
  140. w.Header().Set("Content-Type", "application/json")
  141. r.ParseForm()
  142. marker := r.Form.Get("marker")
  143. switch marker {
  144. case "":
  145. fmt.Fprintf(w, output)
  146. case "49181cd6-169a-4130-9455-31185bbfc5bf":
  147. fmt.Fprintf(w, `{"resources":[]}`)
  148. default:
  149. t.Fatalf("Unexpected marker: [%s]", marker)
  150. }
  151. })
  152. }
  153. // GetExpected represents the expected object from a Get request.
  154. var GetExpected = &stackresources.Resource{
  155. Name: "wordpress_instance",
  156. Links: []gophercloud.Link{
  157. {
  158. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance",
  159. Rel: "self",
  160. },
  161. {
  162. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e",
  163. Rel: "stack",
  164. },
  165. },
  166. LogicalID: "wordpress_instance",
  167. Attributes: map[string]interface{}{"SXSW": "atx"},
  168. StatusReason: "state changed",
  169. UpdatedTime: time.Date(2014, 12, 10, 18, 34, 35, 0, time.UTC),
  170. RequiredBy: []interface{}{},
  171. Status: "CREATE_COMPLETE",
  172. PhysicalID: "00e3a2fe-c65d-403c-9483-4db9930dd194",
  173. Type: "OS::Nova::Server",
  174. }
  175. // GetOutput represents the response body from a Get request.
  176. const GetOutput = `
  177. {
  178. "resource": {
  179. "description": "Some resource",
  180. "attributes": {"SXSW": "atx"},
  181. "resource_name": "wordpress_instance",
  182. "description": "",
  183. "links": [
  184. {
  185. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance",
  186. "rel": "self"
  187. },
  188. {
  189. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e",
  190. "rel": "stack"
  191. }
  192. ],
  193. "logical_resource_id": "wordpress_instance",
  194. "resource_status": "CREATE_COMPLETE",
  195. "updated_time": "2014-12-10T18:34:35",
  196. "required_by": [],
  197. "resource_status_reason": "state changed",
  198. "physical_resource_id": "00e3a2fe-c65d-403c-9483-4db9930dd194",
  199. "resource_type": "OS::Nova::Server"
  200. }
  201. }`
  202. // HandleGetSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance`
  203. // on the test handler mux that responds with a `Get` response.
  204. func HandleGetSuccessfully(t *testing.T, output string) {
  205. th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", func(w http.ResponseWriter, r *http.Request) {
  206. th.TestMethod(t, r, "GET")
  207. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  208. th.TestHeader(t, r, "Accept", "application/json")
  209. w.Header().Set("Content-Type", "application/json")
  210. w.WriteHeader(http.StatusOK)
  211. fmt.Fprintf(w, output)
  212. })
  213. }
  214. // MetadataExpected represents the expected object from a Metadata request.
  215. var MetadataExpected = map[string]string{
  216. "number": "7",
  217. "animal": "auk",
  218. }
  219. // MetadataOutput represents the response body from a Metadata request.
  220. const MetadataOutput = `
  221. {
  222. "metadata": {
  223. "number": "7",
  224. "animal": "auk"
  225. }
  226. }`
  227. // HandleMetadataSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata`
  228. // on the test handler mux that responds with a `Metadata` response.
  229. func HandleMetadataSuccessfully(t *testing.T, output string) {
  230. th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata", func(w http.ResponseWriter, r *http.Request) {
  231. th.TestMethod(t, r, "GET")
  232. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  233. th.TestHeader(t, r, "Accept", "application/json")
  234. w.Header().Set("Content-Type", "application/json")
  235. w.WriteHeader(http.StatusOK)
  236. fmt.Fprintf(w, output)
  237. })
  238. }
  239. // ListTypesExpected represents the expected object from a ListTypes request.
  240. var ListTypesExpected = stackresources.ResourceTypes{
  241. "OS::Nova::Server",
  242. "OS::Heat::RandomString",
  243. "OS::Swift::Container",
  244. "OS::Trove::Instance",
  245. "OS::Nova::FloatingIPAssociation",
  246. "OS::Cinder::VolumeAttachment",
  247. "OS::Nova::FloatingIP",
  248. "OS::Nova::KeyPair",
  249. }
  250. // same as above, but sorted
  251. var SortedListTypesExpected = stackresources.ResourceTypes{
  252. "OS::Cinder::VolumeAttachment",
  253. "OS::Heat::RandomString",
  254. "OS::Nova::FloatingIP",
  255. "OS::Nova::FloatingIPAssociation",
  256. "OS::Nova::KeyPair",
  257. "OS::Nova::Server",
  258. "OS::Swift::Container",
  259. "OS::Trove::Instance",
  260. }
  261. // ListTypesOutput represents the response body from a ListTypes request.
  262. const ListTypesOutput = `
  263. {
  264. "resource_types": [
  265. "OS::Nova::Server",
  266. "OS::Heat::RandomString",
  267. "OS::Swift::Container",
  268. "OS::Trove::Instance",
  269. "OS::Nova::FloatingIPAssociation",
  270. "OS::Cinder::VolumeAttachment",
  271. "OS::Nova::FloatingIP",
  272. "OS::Nova::KeyPair"
  273. ]
  274. }`
  275. // HandleListTypesSuccessfully creates an HTTP handler at `/resource_types`
  276. // on the test handler mux that responds with a `ListTypes` response.
  277. func HandleListTypesSuccessfully(t *testing.T, output string) {
  278. th.Mux.HandleFunc("/resource_types", func(w http.ResponseWriter, r *http.Request) {
  279. th.TestMethod(t, r, "GET")
  280. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  281. th.TestHeader(t, r, "Accept", "application/json")
  282. w.Header().Set("Content-Type", "application/json")
  283. w.WriteHeader(http.StatusOK)
  284. fmt.Fprintf(w, output)
  285. })
  286. }
  287. // GetSchemaExpected represents the expected object from a Schema request.
  288. var GetSchemaExpected = &stackresources.TypeSchema{
  289. Attributes: map[string]interface{}{
  290. "an_attribute": map[string]interface{}{
  291. "description": "An attribute description .",
  292. },
  293. },
  294. Properties: map[string]interface{}{
  295. "a_property": map[string]interface{}{
  296. "update_allowed": false,
  297. "required": true,
  298. "type": "string",
  299. "description": "A resource description.",
  300. },
  301. },
  302. ResourceType: "OS::Heat::AResourceName",
  303. SupportStatus: map[string]interface{}{
  304. "message": "A status message",
  305. "status": "SUPPORTED",
  306. "version": "2014.1",
  307. },
  308. }
  309. // GetSchemaOutput represents the response body from a Schema request.
  310. const GetSchemaOutput = `
  311. {
  312. "attributes": {
  313. "an_attribute": {
  314. "description": "An attribute description ."
  315. }
  316. },
  317. "properties": {
  318. "a_property": {
  319. "update_allowed": false,
  320. "required": true,
  321. "type": "string",
  322. "description": "A resource description."
  323. }
  324. },
  325. "resource_type": "OS::Heat::AResourceName",
  326. "support_status": {
  327. "message": "A status message",
  328. "status": "SUPPORTED",
  329. "version": "2014.1"
  330. }
  331. }`
  332. // HandleGetSchemaSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName`
  333. // on the test handler mux that responds with a `Schema` response.
  334. func HandleGetSchemaSuccessfully(t *testing.T, output string) {
  335. th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName", func(w http.ResponseWriter, r *http.Request) {
  336. th.TestMethod(t, r, "GET")
  337. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  338. th.TestHeader(t, r, "Accept", "application/json")
  339. w.Header().Set("Content-Type", "application/json")
  340. w.WriteHeader(http.StatusOK)
  341. fmt.Fprintf(w, output)
  342. })
  343. }
  344. // GetTemplateExpected represents the expected object from a Template request.
  345. var GetTemplateExpected = "{\n \"HeatTemplateFormatVersion\": \"2012-12-12\",\n \"Outputs\": {\n \"private_key\": {\n \"Description\": \"The private key if it has been saved.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"private_key\\\"]}\"\n },\n \"public_key\": {\n \"Description\": \"The public key.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"public_key\\\"]}\"\n }\n },\n \"Parameters\": {\n \"name\": {\n \"Description\": \"The name of the key pair.\",\n \"Type\": \"String\"\n },\n \"public_key\": {\n \"Description\": \"The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.\",\n \"Type\": \"String\"\n },\n \"save_private_key\": {\n \"AllowedValues\": [\n \"True\",\n \"true\",\n \"False\",\n \"false\"\n ],\n \"Default\": false,\n \"Description\": \"True if the system should remember a generated private key; False otherwise.\",\n \"Type\": \"String\"\n }\n },\n \"Resources\": {\n \"KeyPair\": {\n \"Properties\": {\n \"name\": {\n \"Ref\": \"name\"\n },\n \"public_key\": {\n \"Ref\": \"public_key\"\n },\n \"save_private_key\": {\n \"Ref\": \"save_private_key\"\n }\n },\n \"Type\": \"OS::Nova::KeyPair\"\n }\n }\n}"
  346. // GetTemplateOutput represents the response body from a Template request.
  347. const GetTemplateOutput = `
  348. {
  349. "HeatTemplateFormatVersion": "2012-12-12",
  350. "Outputs": {
  351. "private_key": {
  352. "Description": "The private key if it has been saved.",
  353. "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}"
  354. },
  355. "public_key": {
  356. "Description": "The public key.",
  357. "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}"
  358. }
  359. },
  360. "Parameters": {
  361. "name": {
  362. "Description": "The name of the key pair.",
  363. "Type": "String"
  364. },
  365. "public_key": {
  366. "Description": "The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.",
  367. "Type": "String"
  368. },
  369. "save_private_key": {
  370. "AllowedValues": [
  371. "True",
  372. "true",
  373. "False",
  374. "false"
  375. ],
  376. "Default": false,
  377. "Description": "True if the system should remember a generated private key; False otherwise.",
  378. "Type": "String"
  379. }
  380. },
  381. "Resources": {
  382. "KeyPair": {
  383. "Properties": {
  384. "name": {
  385. "Ref": "name"
  386. },
  387. "public_key": {
  388. "Ref": "public_key"
  389. },
  390. "save_private_key": {
  391. "Ref": "save_private_key"
  392. }
  393. },
  394. "Type": "OS::Nova::KeyPair"
  395. }
  396. }
  397. }`
  398. // HandleGetTemplateSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName/template`
  399. // on the test handler mux that responds with a `Template` response.
  400. func HandleGetTemplateSuccessfully(t *testing.T, output string) {
  401. th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName/template", func(w http.ResponseWriter, r *http.Request) {
  402. th.TestMethod(t, r, "GET")
  403. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  404. th.TestHeader(t, r, "Accept", "application/json")
  405. w.Header().Set("Content-Type", "application/json")
  406. w.WriteHeader(http.StatusOK)
  407. fmt.Fprintf(w, output)
  408. })
  409. }