blob: 3f909467eb3fad752448707a7df373e63bde97f9 [file] [log] [blame]
Mikko Valkonen20de7802016-10-24 22:25:01 +03001package testing
2
3import (
4 "fmt"
5 th "github.com/gophercloud/gophercloud/testhelper"
6 fake "github.com/gophercloud/gophercloud/testhelper/client"
7 "net/http"
8 "testing"
9)
10
11const (
12 shareEndpoint = "/shares"
13)
14
15var createRequest = `{
16 "share": {
17 "name": "my_test_share",
18 "size": 1,
19 "share_proto": "NFS"
20 }
21 }`
22
23var createResponse = `{
24 "share": {
25 "name": "my_test_share",
26 "share_proto": "NFS",
27 "size": 1,
28 "status": null,
29 "share_server_id": null,
30 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
31 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7",
32 "share_type_name": "default",
33 "availability_zone": null,
34 "created_at": "2015-09-18T10:25:24.533287",
35 "export_location": null,
36 "links": [
37 {
38 "href": "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
39 "rel": "self"
40 },
41 {
42 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
43 "rel": "bookmark"
44 }
45 ],
46 "share_network_id": null,
47 "export_locations": [],
48 "host": null,
49 "access_rules_status": "active",
50 "has_replicas": false,
51 "replication_type": null,
52 "task_state": null,
53 "snapshot_support": true,
54 "consistency_group_id": "9397c191-8427-4661-a2e8-b23820dc01d4",
55 "source_cgsnapshot_member_id": null,
56 "volume_type": "default",
57 "snapshot_id": null,
58 "is_public": true,
59 "metadata": {
60 "project": "my_app",
61 "aim": "doc"
62 },
63 "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264",
64 "description": "My custom share London"
65 }
66 }`
67
68// MockCreateResponse creates a mock response
69func MockCreateResponse(t *testing.T) {
70 th.Mux.HandleFunc(shareEndpoint, func(w http.ResponseWriter, r *http.Request) {
71 th.TestMethod(t, r, "POST")
72 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
73 th.TestHeader(t, r, "Content-Type", "application/json")
74 th.TestHeader(t, r, "Accept", "application/json")
75 th.TestJSONRequest(t, r, createRequest)
76 w.Header().Add("Content-Type", "application/json")
77 w.WriteHeader(http.StatusOK)
78 fmt.Fprintf(w, createResponse)
79 })
80}