forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
131 lines (118 loc) · 3.44 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
package testing
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/gophercloud/gophercloud/openstack/clustering/v1/events"
th "github.com/gophercloud/gophercloud/testhelper"
fake "github.com/gophercloud/gophercloud/testhelper/client"
)
const ListResponse = `
{
"events": [
{
"action": "CLUSTER_CREATE",
"cluster": null,
"cluster_id": null,
"id": "edce3528-864f-41fb-8759-f4707925cc09",
"level": "INFO",
"meta_data": {},
"oid": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
"oname": "cluster001",
"otype": "CLUSTER",
"project": "f1fe61dcda2f4618a14c10dc7abc214d",
"status": "start",
"status_reason": "Initializing",
"timestamp": "2015-03-05T08:53:15Z",
"user": "8bcd2cdca7684c02afc9e4f2fc0f0c79"
},
{
"action": "NODE_DELETE",
"cluster": null,
"cluster_id": null,
"id": "abcd1234-864f-41fb-8759-f4707925dd10",
"level": "INFO",
"meta_data": {},
"oid": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
"oname": "node119",
"otype": "node",
"project": "f1fe61dcda2f4618a14c10dc7abc214d",
"status": "start",
"status_reason": "84492c96",
"timestamp": "2015-03-06T18:53:15Z",
"user": "8bcd2cdca7684c02afc9e4f2fc0f0c79"
}
]
}
`
const GetResponse = `
{
"event": {
"action": "CLUSTER_CREATE",
"cluster_id": null,
"id": "edce3528-864f-41fb-8759-f4707925cc09",
"level": "INFO",
"meta_data": {},
"oid": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
"oname": "cluster001",
"otype": "CLUSTER",
"project": "f1fe61dcda2f4618a14c10dc7abc214d",
"status": "start",
"status_reason": "Initializing",
"timestamp": "2015-03-05T08:53:15Z",
"user": "8bcd2cdca7684c02afc9e4f2fc0f0c79"
}
}
`
var ExpectedEvent1 = events.Event{
Action: "CLUSTER_CREATE",
Cluster: "",
ClusterID: "",
ID: "edce3528-864f-41fb-8759-f4707925cc09",
Level: "INFO",
Metadata: map[string]interface{}{},
OID: "0df0931b-e251-4f2e-8719-4ebfda3627ba",
OName: "cluster001",
OType: "CLUSTER",
Project: "f1fe61dcda2f4618a14c10dc7abc214d",
Status: "start",
StatusReason: "Initializing",
Timestamp: time.Date(2015, 3, 5, 8, 53, 15, 0, time.UTC),
User: "8bcd2cdca7684c02afc9e4f2fc0f0c79",
}
var ExpectedEvent2 = events.Event{
Action: "NODE_DELETE",
Cluster: "",
ClusterID: "",
ID: "abcd1234-864f-41fb-8759-f4707925dd10",
Level: "INFO",
Metadata: map[string]interface{}{},
OID: "0df0931b-e251-4f2e-8719-4ebfda3627ba",
OName: "node119",
OType: "node",
Project: "f1fe61dcda2f4618a14c10dc7abc214d",
Status: "start",
StatusReason: "84492c96",
Timestamp: time.Date(2015, 3, 6, 18, 53, 15, 0, time.UTC),
User: "8bcd2cdca7684c02afc9e4f2fc0f0c79",
}
var ExpectedEvents = []events.Event{ExpectedEvent1, ExpectedEvent2}
func HandleListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v1/events", 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, ListResponse)
})
}
func HandleGetSuccessfully(t *testing.T, id string) {
th.Mux.HandleFunc("/v1/events/"+id, 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, GetResponse)
})
}