github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/receivers/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/gophercloud/gophercloud/openstack/clustering/v1/receivers" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 fake "github.com/gophercloud/gophercloud/testhelper/client" 12 ) 13 14 const CreateResponse = ` 15 { 16 "receiver": { 17 "action": "CLUSTER_SCALE_OUT", 18 "actor": { 19 "trust_id": [ 20 "6dc6d336e3fc4c0a951b5698cd1236d9" 21 ] 22 }, 23 "channel": { 24 "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" 25 }, 26 "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", 27 "created_at": "2015-11-04T05:21:41Z", 28 "domain": "Default", 29 "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", 30 "name": "cluster_inflate", 31 "params": { 32 "count": "1" 33 }, 34 "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", 35 "type": "webhook", 36 "updated_at": "2016-11-04T05:21:41Z", 37 "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" 38 } 39 }` 40 41 var ExpectedReceiver = receivers.Receiver{ 42 Action: "CLUSTER_SCALE_OUT", 43 Actor: map[string]interface{}{ 44 "trust_id": []string{ 45 "6dc6d336e3fc4c0a951b5698cd1236d9", 46 }, 47 }, 48 Channel: map[string]interface{}{ 49 "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1", 50 }, 51 ClusterID: "ae63a10b-4a90-452c-aef1-113a0b255ee3", 52 CreatedAt: time.Date(2015, 11, 4, 5, 21, 41, 0, time.UTC), 53 Domain: "Default", 54 ID: "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", 55 Name: "cluster_inflate", 56 Params: map[string]interface{}{ 57 "count": "1", 58 }, 59 Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", 60 Type: "webhook", 61 UpdatedAt: time.Date(2016, 11, 4, 5, 21, 41, 0, time.UTC), 62 User: "b4ad2d6e18cc2b9c48049f6dbe8a5b3c", 63 } 64 65 const GetResponse = ` 66 { 67 "receiver": { 68 "action": "CLUSTER_SCALE_OUT", 69 "actor": { 70 "trust_id": [ 71 "6dc6d336e3fc4c0a951b5698cd1236d9" 72 ] 73 }, 74 "channel": { 75 "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" 76 }, 77 "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", 78 "created_at": "2015-11-04T05:21:41Z", 79 "domain": "Default", 80 "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", 81 "name": "cluster_inflate", 82 "params": { 83 "count": "1" 84 }, 85 "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", 86 "type": "webhook", 87 "updated_at": "2016-11-04T05:21:41Z", 88 "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" 89 } 90 }` 91 92 const UpdateResponse = ` 93 { 94 "receiver": { 95 "action": "CLUSTER_SCALE_OUT", 96 "actor": { 97 "trust_id": [ 98 "6dc6d336e3fc4c0a951b5698cd1236d9" 99 ] 100 }, 101 "channel": { 102 "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" 103 }, 104 "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", 105 "created_at": "2015-06-27T05:09:43Z", 106 "domain": "Default", 107 "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", 108 "name": "cluster_inflate", 109 "params": { 110 "count": "1" 111 }, 112 "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", 113 "type": "webhook", 114 "updated_at": null, 115 "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" 116 } 117 }` 118 119 var ExpectedUpdateReceiver = receivers.Receiver{ 120 Action: "CLUSTER_SCALE_OUT", 121 Actor: map[string]interface{}{ 122 "trust_id": []string{ 123 "6dc6d336e3fc4c0a951b5698cd1236d9", 124 }, 125 }, 126 Channel: map[string]interface{}{ 127 "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1", 128 }, 129 ClusterID: "ae63a10b-4a90-452c-aef1-113a0b255ee3", 130 CreatedAt: time.Date(2015, 6, 27, 5, 9, 43, 0, time.UTC), 131 Domain: "Default", 132 ID: "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", 133 Name: "cluster_inflate", 134 Params: map[string]interface{}{ 135 "count": "1", 136 }, 137 Project: "6e18cc2bdbeb48a5b3cad2dc499f6804", 138 Type: "webhook", 139 User: "b4ad2d6e18cc2b9c48049f6dbe8a5b3c", 140 } 141 142 const ListResponse = ` 143 { 144 "receivers": [ 145 { 146 "action": "CLUSTER_SCALE_OUT", 147 "actor": { 148 "trust_id": [ 149 "6dc6d336e3fc4c0a951b5698cd1236d9" 150 ] 151 }, 152 "channel": { 153 "alarm_url": "http://node1:8778/v1/webhooks/e03dd2e5-8f2e-4ec1-8c6a-74ba891e5422/trigger?V=1&count=1" 154 }, 155 "cluster_id": "ae63a10b-4a90-452c-aef1-113a0b255ee3", 156 "created_at": "2015-06-27T05:09:43Z", 157 "domain": "Default", 158 "id": "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", 159 "name": "cluster_inflate", 160 "params": { 161 "count": "1" 162 }, 163 "project": "6e18cc2bdbeb48a5b3cad2dc499f6804", 164 "type": "webhook", 165 "updated_at": null, 166 "user": "b4ad2d6e18cc2b9c48049f6dbe8a5b3c" 167 } 168 ] 169 }` 170 171 var ExpectedReceiversList = []receivers.Receiver{ExpectedUpdateReceiver} 172 var ExpectedNotifyRequestID = "66a81d68-bf48-4af5-897b-a3bfef7279a8" 173 174 func HandleCreateSuccessfully(t *testing.T) { 175 th.Mux.HandleFunc("/v1/receivers", func(w http.ResponseWriter, r *http.Request) { 176 th.TestMethod(t, r, "POST") 177 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 178 179 w.Header().Add("Content-Type", "application/json") 180 w.WriteHeader(http.StatusOK) 181 182 fmt.Fprint(w, CreateResponse) 183 }) 184 } 185 186 func HandleGetSuccessfully(t *testing.T) { 187 th.Mux.HandleFunc("/v1/receivers/573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", func(w http.ResponseWriter, r *http.Request) { 188 th.TestMethod(t, r, "GET") 189 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 190 191 w.Header().Add("Content-Type", "application/json") 192 w.WriteHeader(http.StatusOK) 193 194 fmt.Fprint(w, GetResponse) 195 }) 196 } 197 198 func HandleUpdateSuccessfully(t *testing.T) { 199 th.Mux.HandleFunc("/v1/receivers/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { 200 th.TestMethod(t, r, "PATCH") 201 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 202 203 w.Header().Add("Content-Type", "application/json") 204 w.WriteHeader(http.StatusOK) 205 206 fmt.Fprint(w, UpdateResponse) 207 }) 208 } 209 210 func HandleListSuccessfully(t *testing.T) { 211 th.Mux.HandleFunc("/v1/receivers", func(w http.ResponseWriter, r *http.Request) { 212 th.TestMethod(t, r, "GET") 213 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 214 th.TestFormValues(t, r, map[string]string{"limit": "2", "sort": "name:asc,status:desc"}) 215 w.Header().Add("Content-Type", "application/json") 216 w.WriteHeader(http.StatusOK) 217 218 fmt.Fprint(w, ListResponse) 219 }) 220 } 221 222 func HandleDeleteSuccessfully(t *testing.T) { 223 th.Mux.HandleFunc("/v1/receivers/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { 224 th.TestMethod(t, r, "DELETE") 225 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 226 227 w.Header().Add("Content-Type", "application/json") 228 w.WriteHeader(http.StatusNoContent) 229 }) 230 } 231 232 func HandleNotifySuccessfully(t *testing.T) { 233 th.Mux.HandleFunc("/v1/receivers/6dc6d336e3fc4c0a951b5698cd1236ee/notify", func(w http.ResponseWriter, r *http.Request) { 234 th.TestMethod(t, r, "POST") 235 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 236 237 w.Header().Add("Content-Type", "application/json") 238 w.Header().Add("X-OpenStack-Request-Id", ExpectedNotifyRequestID) 239 w.WriteHeader(http.StatusNoContent) 240 }) 241 }