blob: 00bdfe0a2b9d1047cc0122458c24da8d7c1cae10 [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}