blob: 83b174f64305827557f6202b5a5fa03b0303953a [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"
Mikko Valkonen4c108b52016-10-24 23:11:25 +030013 shareID = "011d21e2-fbc3-4e4a-9993-9ea223f73264"
Mikko Valkonen20de7802016-10-24 22:25:01 +030014)
15
16var createRequest = `{
17 "share": {
18 "name": "my_test_share",
19 "size": 1,
20 "share_proto": "NFS"
21 }
22 }`
23
24var createResponse = `{
25 "share": {
26 "name": "my_test_share",
27 "share_proto": "NFS",
28 "size": 1,
29 "status": null,
30 "share_server_id": null,
31 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
32 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7",
33 "share_type_name": "default",
34 "availability_zone": null,
35 "created_at": "2015-09-18T10:25:24.533287",
36 "export_location": null,
37 "links": [
38 {
39 "href": "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
40 "rel": "self"
41 },
42 {
43 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
44 "rel": "bookmark"
45 }
46 ],
47 "share_network_id": null,
48 "export_locations": [],
49 "host": null,
50 "access_rules_status": "active",
51 "has_replicas": false,
52 "replication_type": null,
53 "task_state": null,
54 "snapshot_support": true,
55 "consistency_group_id": "9397c191-8427-4661-a2e8-b23820dc01d4",
56 "source_cgsnapshot_member_id": null,
57 "volume_type": "default",
58 "snapshot_id": null,
59 "is_public": true,
60 "metadata": {
61 "project": "my_app",
62 "aim": "doc"
63 },
64 "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264",
65 "description": "My custom share London"
66 }
67 }`
68
69// MockCreateResponse creates a mock response
70func MockCreateResponse(t *testing.T) {
71 th.Mux.HandleFunc(shareEndpoint, func(w http.ResponseWriter, r *http.Request) {
72 th.TestMethod(t, r, "POST")
73 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
74 th.TestHeader(t, r, "Content-Type", "application/json")
75 th.TestHeader(t, r, "Accept", "application/json")
76 th.TestJSONRequest(t, r, createRequest)
77 w.Header().Add("Content-Type", "application/json")
78 w.WriteHeader(http.StatusOK)
79 fmt.Fprintf(w, createResponse)
80 })
81}
Mikko Valkonen4c108b52016-10-24 23:11:25 +030082
83// MockDeleteResponse creates a mock delete response
84func MockDeleteResponse(t *testing.T) {
85 th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) {
86 th.TestMethod(t, r, "DELETE")
87 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
88 w.WriteHeader(http.StatusAccepted)
89 })
90}
Mikko Valkonend887d2a2016-10-25 21:00:09 +030091
92var getResponse = `{
93 "share": {
94 "links": [
95 {
96 "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
97 "rel": "self"
98 },
99 {
100 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
101 "rel": "bookmark"
102 }
103 ],
104 "availability_zone": "nova",
105 "share_network_id": "713df749-aac0-4a54-af52-10f6c991e80c",
106 "share_server_id": "e268f4aa-d571-43dd-9ab3-f49ad06ffaef",
107 "snapshot_id": null,
108 "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264",
109 "size": 1,
110 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7",
111 "share_type_name": "default",
112 "consistency_group_id": "9397c191-8427-4661-a2e8-b23820dc01d4",
113 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
114 "metadata": {
115 "project": "my_app",
116 "aim": "doc"
117 },
118 "status": "available",
119 "description": "My custom share London",
120 "host": "manila2@generic1#GENERIC1",
121 "has_replicas": false,
122 "replication_type": null,
123 "task_state": null,
124 "is_public": true,
125 "snapshot_support": true,
126 "name": "my_test_share",
127 "created_at": "2015-09-18T10:25:24.000000",
128 "share_proto": "NFS",
129 "volume_type": "default",
130 "source_cgsnapshot_member_id": null
131 }
132}`
133
134// MockGetResponse creates a mock get response
135func MockGetResponse(t *testing.T) {
136 th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) {
137 th.TestMethod(t, r, "GET")
138 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
139 w.WriteHeader(http.StatusOK)
140 fmt.Fprintf(w, getResponse)
141 })
142}