/
fixtures.go
93 lines (85 loc) · 3.07 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
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/gophercloud/gophercloud/openstack/identity/v3/limits"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
// ListOutput provides a single page of List results.
const ListOutput = `
{
"links": {
"self": "http://10.3.150.25/identity/v3/limits",
"previous": null,
"next": null
},
"limits": [
{
"resource_name": "volume",
"region_id": null,
"links": {
"self": "http://10.3.150.25/identity/v3/limits/25a04c7a065c430590881c646cdcdd58"
},
"service_id": "9408080f1970482aa0e38bc2d4ea34b7",
"project_id": "3a705b9f56bb439381b43c4fe59dccce",
"domain_id": null,
"id": "25a04c7a065c430590881c646cdcdd58",
"resource_limit": 11,
"description": "Number of volumes for project 3a705b9f56bb439381b43c4fe59dccce"
},
{
"resource_name": "snapshot",
"region_id": "RegionOne",
"links": {
"self": "http://10.3.150.25/identity/v3/limits/3229b3849f584faea483d6851f7aab05"
},
"service_id": "9408080f1970482aa0e38bc2d4ea34b7",
"project_id": "3a705b9f56bb439381b43c4fe59dccce",
"domain_id": null,
"id": "3229b3849f584faea483d6851f7aab05",
"resource_limit": 5,
"description": null
}
]
}
`
// FirstLimit is the first limit in the List request.
var FirstLimit = limits.Limit{
ResourceName: "volume",
Links: map[string]interface{}{
"self": "http://10.3.150.25/identity/v3/limits/25a04c7a065c430590881c646cdcdd58",
},
ServiceID: "9408080f1970482aa0e38bc2d4ea34b7",
ProjectID: "3a705b9f56bb439381b43c4fe59dccce",
ID: "25a04c7a065c430590881c646cdcdd58",
ResourceLimit: 11,
Description: "Number of volumes for project 3a705b9f56bb439381b43c4fe59dccce",
}
// SecondLimit is the second limit in the List request.
var SecondLimit = limits.Limit{
ResourceName: "snapshot",
RegionID: "RegionOne",
Links: map[string]interface{}{
"self": "http://10.3.150.25/identity/v3/limits/3229b3849f584faea483d6851f7aab05",
},
ServiceID: "9408080f1970482aa0e38bc2d4ea34b7",
ProjectID: "3a705b9f56bb439381b43c4fe59dccce",
ID: "3229b3849f584faea483d6851f7aab05",
ResourceLimit: 5,
}
// ExpectedLimitsSlice is the slice of limits expected to be returned from ListOutput.
var ExpectedLimitsSlice = []limits.Limit{FirstLimit, SecondLimit}
// HandleListLimitsSuccessfully creates an HTTP handler at `/limits` on the
// test handler mux that responds with a list of two limits.
func HandleListLimitsSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/limits", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, ListOutput)
})
}