forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
137 lines (131 loc) · 4.53 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package testing
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/chjlangzi/gophercloud/openstack/compute/v2/extensions/usage"
th "github.com/chjlangzi/gophercloud/testhelper"
"github.com/chjlangzi/gophercloud/testhelper/client"
)
const FirstTenantID = "aabbccddeeff112233445566"
// GetSingleTenant holds the fixtures for the content of the request for a
// single tenant.
const GetSingleTenant = `{
"tenant_usage": {
"server_usages": [
{
"ended_at": null,
"flavor": "m1.tiny",
"hours": 0.021675453333333334,
"instance_id": "a70096fd-8196-406b-86c4-045840f53ad7",
"local_gb": 1,
"memory_mb": 512,
"name": "jttest",
"started_at": "2017-11-30T03:23:43.000000",
"state": "active",
"tenant_id": "aabbccddeeff112233445566",
"uptime": 78,
"vcpus": 1
},
{
"ended_at": "2017-11-21T04:10:11.000000",
"flavor": "m1.acctest",
"hours": 0.33444444444444443,
"instance_id": "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd",
"local_gb": 15,
"memory_mb": 512,
"name": "basic",
"started_at": "2017-11-21T03:50:07.000000",
"state": "terminated",
"tenant_id": "aabbccddeeff112233445566",
"uptime": 1204,
"vcpus": 1
},
{
"ended_at": "2017-11-30T03:21:21.000000",
"flavor": "m1.acctest",
"hours": 0.004166666666666667,
"instance_id": "ceb654fa-e0e8-44fb-8942-e4d0bfad3941",
"local_gb": 15,
"memory_mb": 512,
"name": "ACPTTESTJSxbPQAC34lTnBE1",
"started_at": "2017-11-30T03:21:06.000000",
"state": "terminated",
"tenant_id": "aabbccddeeff112233445566",
"uptime": 15,
"vcpus": 1
}
],
"start": "2017-11-02T03:25:01.000000",
"stop": "2017-11-30T03:25:01.000000",
"tenant_id": "aabbccddeeff112233445566",
"total_hours": 1.25834212,
"total_local_gb_usage": 18.571675453333334,
"total_memory_mb_usage": 644.27116544,
"total_vcpus_usage": 1.25834212
}
}`
// HandleGetSingleTenantSuccessfully configures the test server to respond to a
// Get request for a single tenant
func HandleGetSingleTenantSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-simple-tenant-usage/"+FirstTenantID, 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.Fprint(w, GetSingleTenant)
})
}
// SingleTenantUsageResults is the code fixture for GetSingleTenant.
var SingleTenantUsageResults = usage.TenantUsage{
ServerUsages: []usage.ServerUsage{
{
Flavor: "m1.tiny",
Hours: 0.021675453333333334,
InstanceID: "a70096fd-8196-406b-86c4-045840f53ad7",
LocalGB: 1,
MemoryMB: 512,
Name: "jttest",
StartedAt: time.Date(2017, 11, 30, 3, 23, 43, 0, time.UTC),
State: "active",
TenantID: "aabbccddeeff112233445566",
Uptime: 78,
VCPUs: 1,
},
{
Flavor: "m1.acctest",
Hours: 0.33444444444444443,
InstanceID: "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd",
LocalGB: 15,
MemoryMB: 512,
Name: "basic",
StartedAt: time.Date(2017, 11, 21, 3, 50, 7, 0, time.UTC),
EndedAt: time.Date(2017, 11, 21, 4, 10, 11, 0, time.UTC),
State: "terminated",
TenantID: "aabbccddeeff112233445566",
Uptime: 1204,
VCPUs: 1,
},
{
Flavor: "m1.acctest",
Hours: 0.004166666666666667,
InstanceID: "ceb654fa-e0e8-44fb-8942-e4d0bfad3941",
LocalGB: 15,
MemoryMB: 512,
Name: "ACPTTESTJSxbPQAC34lTnBE1",
StartedAt: time.Date(2017, 11, 30, 3, 21, 6, 0, time.UTC),
EndedAt: time.Date(2017, 11, 30, 3, 21, 21, 0, time.UTC),
State: "terminated",
TenantID: "aabbccddeeff112233445566",
Uptime: 15,
VCPUs: 1,
},
},
Start: time.Date(2017, 11, 2, 3, 25, 1, 0, time.UTC),
Stop: time.Date(2017, 11, 30, 3, 25, 1, 0, time.UTC),
TenantID: "aabbccddeeff112233445566",
TotalHours: 1.25834212,
TotalLocalGBUsage: 18.571675453333334,
TotalMemoryMBUsage: 644.27116544,
TotalVCPUsUsage: 1.25834212,
}