forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
115 lines (104 loc) · 4.96 KB
/
fixtures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package testing
import (
"fmt"
"net/http"
"testing"
th "github.com/gophercloud/gophercloud/testhelper"
fake "github.com/gophercloud/gophercloud/testhelper/client"
)
func MockDeleteResponse(t *testing.T) {
th.Mux.HandleFunc("/messages/messageID", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}
func MockListResponse(t *testing.T) {
th.Mux.HandleFunc("/messages", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"messages": [
{
"resource_id": "0d0b883f-95ef-406c-b930-55612ee48a6d",
"message_level": "ERROR",
"user_message": "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.",
"expires_at": "2019-01-06T08:53:38.000000",
"id": "143a6cc2-1998-44d0-8356-22070b0ebdaa",
"created_at": "2018-12-07T08:53:38.000000",
"detail_id": "004",
"request_id": "req-21767eee-22ca-40a4-b6c0-ae7d35cd434f",
"project_id": "a5e9d48232dc4aa59a716b5ced963584",
"resource_type": "SHARE",
"action_id": "002"
},
{
"resource_id": "4336d74f-3bdc-4f27-9657-c01ec63680bf",
"message_level": "ERROR",
"user_message": "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.",
"expires_at": "2019-01-06T08:53:34.000000",
"id": "2076373e-13a7-4b84-9e67-15ce8cceaff8",
"created_at": "2018-12-07T08:53:34.000000",
"detail_id": "004",
"request_id": "req-957792ed-f38b-42db-a86a-850f815cbbe9",
"project_id": "a5e9d48232dc4aa59a716b5ced963584",
"resource_type": "SHARE",
"action_id": "002"
}
]
}`)
})
}
func MockFilteredListResponse(t *testing.T) {
th.Mux.HandleFunc("/messages", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"messages": [
{
"resource_id": "4336d74f-3bdc-4f27-9657-c01ec63680bf",
"message_level": "ERROR",
"user_message": "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.",
"expires_at": "2019-01-06T08:53:34.000000",
"id": "2076373e-13a7-4b84-9e67-15ce8cceaff8",
"created_at": "2018-12-07T08:53:34.000000",
"detail_id": "004",
"request_id": "req-957792ed-f38b-42db-a86a-850f815cbbe9",
"project_id": "a5e9d48232dc4aa59a716b5ced963584",
"resource_type": "SHARE",
"action_id": "002"
}
]
}`)
})
}
func MockGetResponse(t *testing.T) {
th.Mux.HandleFunc("/messages/2076373e-13a7-4b84-9e67-15ce8cceaff8", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"message": {
"resource_id": "4336d74f-3bdc-4f27-9657-c01ec63680bf",
"message_level": "ERROR",
"user_message": "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.",
"expires_at": "2019-01-06T08:53:34.000000",
"id": "2076373e-13a7-4b84-9e67-15ce8cceaff8",
"created_at": "2018-12-07T08:53:34.000000",
"detail_id": "004",
"request_id": "req-957792ed-f38b-42db-a86a-850f815cbbe9",
"project_id": "a5e9d48232dc4aa59a716b5ced963584",
"resource_type": "SHARE",
"action_id": "002"
}
}`)
})
}