github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/sfs/v2/shares/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 fake "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 const ( 13 shareEndpoint = "/shares" 14 shareID = "011d21e2-fbc3-4e4a-9993-9ea223f73264" 15 ) 16 17 var createRequest = `{ 18 "share": { 19 "name": "my_test_share", 20 "size": 1, 21 "share_proto": "NFS" 22 } 23 }` 24 25 var createResponse = `{ 26 "share": { 27 "name": "my_test_share", 28 "share_proto": "NFS", 29 "size": 1, 30 "status": null, 31 "share_server_id": null, 32 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 33 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7", 34 "share_type_name": "default", 35 "availability_zone": null, 36 "created_at": "2015-09-18T10:25:24.533287", 37 "export_location": null, 38 "links": [ 39 { 40 "href": "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 41 "rel": "self" 42 }, 43 { 44 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 45 "rel": "bookmark" 46 } 47 ], 48 "share_network_id": null, 49 "export_locations": [], 50 "host": null, 51 "access_rules_status": "active", 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 69 func 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 } 81 82 var updateRequest = `{ 83 "share": { 84 "display_name": "my_test_share_sfs", 85 "display_description": "test" 86 } 87 }` 88 89 var updateResponse = `{ 90 "share": { 91 "name": "my_test_share_sfs", 92 "share_proto": "NFS", 93 "size": 1, 94 "status": null, 95 "share_server_id": null, 96 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 97 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7", 98 "share_type_name": "default", 99 "availability_zone": null, 100 "created_at": "2015-09-18T10:25:24.533287", 101 "export_location": null, 102 "links": [ 103 { 104 "href": "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 105 "rel": "self" 106 }, 107 { 108 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 109 "rel": "bookmark" 110 } 111 ], 112 "share_network_id": null, 113 "export_locations": [], 114 "host": null, 115 "access_rules_status": "active", 116 "task_state": null, 117 "snapshot_support": true, 118 "consistency_group_id": "9397c191-8427-4661-a2e8-b23820dc01d4", 119 "source_cgsnapshot_member_id": null, 120 "volume_type": "default", 121 "snapshot_id": null, 122 "is_public": true, 123 "metadata": { 124 "project": "my_app", 125 "aim": "doc" 126 }, 127 "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264", 128 "description": "test" 129 } 130 }` 131 132 // MockCreateResponse creates a mock response 133 func MockUpdateResponse(t *testing.T) { 134 th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) { 135 th.TestMethod(t, r, "PUT") 136 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 137 th.TestHeader(t, r, "Content-Type", "application/json") 138 th.TestHeader(t, r, "Accept", "application/json") 139 th.TestJSONRequest(t, r, updateRequest) 140 w.Header().Add("Content-Type", "application/json") 141 w.WriteHeader(http.StatusOK) 142 fmt.Fprintf(w, updateResponse) 143 }) 144 } 145 146 // MockDeleteResponse creates a mock delete response 147 func MockDeleteResponse(t *testing.T) { 148 th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) { 149 th.TestMethod(t, r, "DELETE") 150 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 151 w.WriteHeader(http.StatusAccepted) 152 }) 153 } 154 155 var getResponse = `{ 156 "share": { 157 "links": [ 158 { 159 "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 160 "rel": "self" 161 }, 162 { 163 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 164 "rel": "bookmark" 165 } 166 ], 167 "availability_zone": "nova", 168 "share_network_id": "713df749-aac0-4a54-af52-10f6c991e80c", 169 "snapshot_id": null, 170 "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264", 171 "size": 1, 172 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7", 173 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 174 "metadata": { 175 "project": "my_app", 176 "aim": "doc" 177 }, 178 "status": "available", 179 "description": "My custom share London", 180 "host": "manila2@generic1#GENERIC1", 181 "is_public": true, 182 "name": "my_test_share", 183 "created_at": "2015-09-18T10:25:24.000000", 184 "share_proto": "NFS", 185 "volume_type": "default" 186 } 187 }` 188 189 // MockGetResponse creates a mock get response 190 func MockGetResponse(t *testing.T) { 191 th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) { 192 th.TestMethod(t, r, "GET") 193 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 194 w.WriteHeader(http.StatusOK) 195 fmt.Fprintf(w, getResponse) 196 }) 197 } 198 199 var grantAccessRequest = `{ 200 "os-allow_access": { 201 "access_to": "5232f396-d6cc-4a81-8de3-afd7a7ecdfd8", 202 "access_type": "cert", 203 "access_level": "rw" 204 } 205 }` 206 207 var grantAccessResponse = `{ 208 "access": { 209 "share_id": "1b8facf8-b822-4349-a033-e078b2a84b7f", 210 "access_type": "cert", 211 "access_to": "5232f396-d6cc-4a81-8de3-afd7a7ecdfd8", 212 "access_level": "rw", 213 "state": "new", 214 "id": "fc32500f-fa78-4f06-8caf-06ad7fb9726c" 215 } 216 }` 217 218 var listAccessRightsRequest = `{ 219 "os-access_list": null 220 }` 221 222 var listAccessRightsResponse = `{ 223 "access_list": [ 224 { 225 "access_level": "rw", 226 "state": "active", 227 "id": "5158f095-4c43-49c0-b5a7-c458e85ed8c8", 228 "access_type": "cert", 229 "access_to": "5232f396-d6cc-4a81-8de3-afd7a7ecdfd8" 230 } 231 ] 232 }` 233 234 var deleteAccessRequest = `{ 235 "os-deny_access": { 236 "access_id": "ea07152b-d08b-4f6b-8785-ce64dce52679" 237 } 238 }` 239 240 var getExportLocationsResponse = `{ 241 "export_locations": [ 242 { 243 "path": "sfs-nas1.eu-de.otc.t-systems.com:/share-d41ee18b", 244 "id": "fab962ba-4b9a-475e-a380-8e856ed3f92d" 245 } 246 ] 247 }` 248 249 var listResponse = `{ 250 "shares": [ 251 { 252 "links": [ 253 { 254 "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 255 "rel": "self" 256 }, 257 { 258 "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264", 259 "rel": "bookmark" 260 } 261 ], 262 "availability_zone": "nova", 263 "share_network_id": "713df749-aac0-4a54-af52-10f6c991e80c", 264 "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264", 265 "size": 1, 266 "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7", 267 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 268 "status": "available", 269 "description": "My custom share London", 270 "host": "manila2@generic1#GENERIC1", 271 "is_public": true, 272 "created_at": "2015-09-18T10:25:24.000000", 273 "name": "my_test_share", 274 "share_proto": "NFS", 275 "volume_type": "default" 276 } 277 ] 278 }`