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 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/limits"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
// GetOutput is a sample response to a Get call.
const GetOutput = `
{
"limits": {
"rate": [
{
"regex": ".*",
"uri": "*",
"limit": [
{
"verb": "GET",
"next-available": "1970-01-01T00:00:00",
"unit": "MINUTE",
"value": 10,
"remaining": 10
},
{
"verb": "POST",
"next-available": "1970-01-01T00:00:00",
"unit": "HOUR",
"value": 5,
"remaining": 5
}
]
},
{
"regex": "changes-since",
"uri": "changes-since*",
"limit": [
{
"verb": "GET",
"next-available": "1970-01-01T00:00:00",
"unit": "MINUTE",
"value": 5,
"remaining": 5
}
]
}
],
"absolute": {
"maxTotalVolumes": 40,
"maxTotalSnapshots": 40,
"maxTotalVolumeGigabytes": 1000,
"maxTotalBackups": 10,
"maxTotalBackupGigabytes": 1000,
"totalVolumesUsed": 1,
"totalGigabytesUsed": 100,
"totalSnapshotsUsed": 1,
"totalBackupsUsed": 1,
"totalBackupGigabytesUsed": 50
}
}
}
`
// LimitsResult is the result of the limits in GetOutput.
var LimitsResult = limits.Limits{
Rate: []limits.Rate{
{
Regex: ".*",
URI: "*",
Limit: []limits.Limit{
{
Verb: "GET",
NextAvailable: "1970-01-01T00:00:00",
Unit: "MINUTE",
Value: 10,
Remaining: 10,
},
{
Verb: "POST",
NextAvailable: "1970-01-01T00:00:00",
Unit: "HOUR",
Value: 5,
Remaining: 5,
},
},
},
{
Regex: "changes-since",
URI: "changes-since*",
Limit: []limits.Limit{
{
Verb: "GET",
NextAvailable: "1970-01-01T00:00:00",
Unit: "MINUTE",
Value: 5,
Remaining: 5,
},
},
},
},
Absolute: limits.Absolute{
MaxTotalVolumes: 40,
MaxTotalSnapshots: 40,
MaxTotalVolumeGigabytes: 1000,
MaxTotalBackups: 10,
MaxTotalBackupGigabytes: 1000,
TotalVolumesUsed: 1,
TotalGigabytesUsed: 100,
TotalSnapshotsUsed: 1,
TotalBackupsUsed: 1,
TotalBackupGigabytesUsed: 50,
},
}
// HandleGetSuccessfully configures the test server to respond to a Get request
// for a limit.
func HandleGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/limits", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, GetOutput)
})
}
|