github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dns/v2/recordsets/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/huaweicloud/golangsdk" 10 "github.com/huaweicloud/golangsdk/openstack/dns/v2/recordsets" 11 th "github.com/huaweicloud/golangsdk/testhelper" 12 "github.com/huaweicloud/golangsdk/testhelper/client" 13 ) 14 15 // ListByZoneOutput is a sample response to a ListByZone call. 16 const ListByZoneOutput = ` 17 { 18 "recordsets": [ 19 { 20 "description": "This is an example record set.", 21 "links": { 22 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" 23 }, 24 "updated_at": null, 25 "records": [ 26 "10.1.0.2" 27 ], 28 "ttl": 3600, 29 "id": "f7b10e9b-0cae-4a91-b162-562bc6096648", 30 "name": "example.org.", 31 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 32 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 33 "zone_name": "example.com.", 34 "created_at": "2014-10-24T19:59:44.000000", 35 "version": 1, 36 "type": "A", 37 "status": "PENDING", 38 "action": "CREATE" 39 }, 40 { 41 "description": "This is another example record set.", 42 "links": { 43 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/7423aeaf-b354-4bd7-8aba-2e831567b478" 44 }, 45 "updated_at": "2017-03-04T14:29:07.000000", 46 "records": [ 47 "10.1.0.3", 48 "10.1.0.4" 49 ], 50 "ttl": 3600, 51 "id": "7423aeaf-b354-4bd7-8aba-2e831567b478", 52 "name": "foo.example.org.", 53 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 54 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 55 "zone_name": "example.com.", 56 "created_at": "2014-10-24T19:59:44.000000", 57 "version": 1, 58 "type": "A", 59 "status": "PENDING", 60 "action": "CREATE" 61 } 62 ], 63 "links": { 64 "self": "http://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets" 65 }, 66 "metadata": { 67 "total_count": 2 68 } 69 } 70 ` 71 72 // ListByZoneOutputLimited is a sample response to a ListByZone call with a requested limit. 73 const ListByZoneOutputLimited = ` 74 { 75 "recordsets": [ 76 { 77 "description": "This is another example record set.", 78 "links": { 79 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/7423aeaf-b354-4bd7-8aba-2e831567b478" 80 }, 81 "updated_at": "2017-03-04T14:29:07.000000", 82 "records": [ 83 "10.1.0.3", 84 "10.1.0.4" 85 ], 86 "ttl": 3600, 87 "id": "7423aeaf-b354-4bd7-8aba-2e831567b478", 88 "name": "foo.example.org.", 89 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 90 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 91 "zone_name": "example.com.", 92 "created_at": "2014-10-24T19:59:44.000000", 93 "version": 1, 94 "type": "A", 95 "status": "PENDING", 96 "action": "CREATE" 97 } 98 ], 99 "links": { 100 "self": "http://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets?limit=1" 101 }, 102 "metadata": { 103 "total_count": 1 104 } 105 } 106 ` 107 108 // GetOutput is a sample response to a Get call. 109 const GetOutput = ` 110 { 111 "description": "This is an example record set.", 112 "links": { 113 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" 114 }, 115 "updated_at": null, 116 "records": [ 117 "10.1.0.2" 118 ], 119 "ttl": 3600, 120 "id": "f7b10e9b-0cae-4a91-b162-562bc6096648", 121 "name": "example.org.", 122 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 123 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 124 "zone_name": "example.com.", 125 "created_at": "2014-10-24T19:59:44.000000", 126 "version": 1, 127 "type": "A", 128 "status": "PENDING", 129 "action": "CREATE" 130 } 131 ` 132 133 // NextPageRequest is a sample request to test pagination. 134 const NextPageRequest = ` 135 { 136 "links": { 137 "self": "http://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets?limit=1", 138 "next": "http://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets?limit=1&marker=f7b10e9b-0cae-4a91-b162-562bc6096648" 139 } 140 } 141 ` 142 143 // FirstRecordSet is the first result in ListByZoneOutput 144 var FirstRecordSetCreatedAt, _ = time.Parse(golangsdk.RFC3339MilliNoZ, "2014-10-24T19:59:44.000000") 145 var FirstRecordSet = recordsets.RecordSet{ 146 ID: "f7b10e9b-0cae-4a91-b162-562bc6096648", 147 Description: "This is an example record set.", 148 UpdatedAt: time.Time{}, 149 Records: []string{"10.1.0.2"}, 150 TTL: 3600, 151 Name: "example.org.", 152 ProjectID: "4335d1f0-f793-11e2-b778-0800200c9a66", 153 ZoneID: "2150b1bf-dee2-4221-9d85-11f7886fb15f", 154 ZoneName: "example.com.", 155 CreatedAt: FirstRecordSetCreatedAt, 156 Version: 1, 157 Type: "A", 158 Status: "PENDING", 159 Action: "CREATE", 160 Links: []golangsdk.Link{ 161 { 162 Rel: "self", 163 Href: "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648", 164 }, 165 }, 166 } 167 168 // SecondRecordSet is the first result in ListByZoneOutput 169 var SecondRecordSetCreatedAt, _ = time.Parse(golangsdk.RFC3339MilliNoZ, "2014-10-24T19:59:44.000000") 170 var SecondRecordSetUpdatedAt, _ = time.Parse(golangsdk.RFC3339MilliNoZ, "2017-03-04T14:29:07.000000") 171 var SecondRecordSet = recordsets.RecordSet{ 172 ID: "7423aeaf-b354-4bd7-8aba-2e831567b478", 173 Description: "This is another example record set.", 174 UpdatedAt: SecondRecordSetUpdatedAt, 175 Records: []string{"10.1.0.3", "10.1.0.4"}, 176 TTL: 3600, 177 Name: "foo.example.org.", 178 ProjectID: "4335d1f0-f793-11e2-b778-0800200c9a66", 179 ZoneID: "2150b1bf-dee2-4221-9d85-11f7886fb15f", 180 ZoneName: "example.com.", 181 CreatedAt: SecondRecordSetCreatedAt, 182 Version: 1, 183 Type: "A", 184 Status: "PENDING", 185 Action: "CREATE", 186 Links: []golangsdk.Link{ 187 { 188 Rel: "self", 189 Href: "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/7423aeaf-b354-4bd7-8aba-2e831567b478", 190 }, 191 }, 192 } 193 194 // ExpectedRecordSetSlice is the slice of results that should be parsed 195 // from ListByZoneOutput, in the expected order. 196 var ExpectedRecordSetSlice = []recordsets.RecordSet{FirstRecordSet, SecondRecordSet} 197 198 // ExpectedRecordSetSliceLimited is the slice of limited results that should be parsed 199 // from ListByZoneOutput. 200 var ExpectedRecordSetSliceLimited = []recordsets.RecordSet{SecondRecordSet} 201 202 // HandleListByZoneSuccessfully configures the test server to respond to a ListByZone request. 203 func HandleListByZoneSuccessfully(t *testing.T) { 204 th.Mux.HandleFunc("/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets", 205 func(w http.ResponseWriter, r *http.Request) { 206 th.TestMethod(t, r, "GET") 207 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 208 209 w.Header().Add("Content-Type", "application/json") 210 r.ParseForm() 211 marker := r.Form.Get("marker") 212 switch marker { 213 case "f7b10e9b-0cae-4a91-b162-562bc6096648": 214 fmt.Fprintf(w, ListByZoneOutputLimited) 215 case "": 216 fmt.Fprintf(w, ListByZoneOutput) 217 } 218 }) 219 } 220 221 // HandleGetSuccessfully configures the test server to respond to a Get request. 222 func HandleGetSuccessfully(t *testing.T) { 223 th.Mux.HandleFunc("/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648", 224 func(w http.ResponseWriter, r *http.Request) { 225 th.TestMethod(t, r, "GET") 226 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 227 228 w.Header().Add("Content-Type", "application/json") 229 fmt.Fprintf(w, GetOutput) 230 }) 231 } 232 233 // CreateRecordSetRequest is a sample request to create a resource record. 234 const CreateRecordSetRequest = ` 235 { 236 "name" : "example.org.", 237 "description" : "This is an example record set.", 238 "type" : "A", 239 "ttl" : 3600, 240 "records" : [ 241 "10.1.0.2" 242 ] 243 } 244 ` 245 246 // CreateRecordSetResponse is a sample response to a create request. 247 const CreateRecordSetResponse = ` 248 { 249 "description": "This is an example record set.", 250 "links": { 251 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" 252 }, 253 "updated_at": null, 254 "records": [ 255 "10.1.0.2" 256 ], 257 "ttl": 3600, 258 "id": "f7b10e9b-0cae-4a91-b162-562bc6096648", 259 "name": "example.org.", 260 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 261 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 262 "zone_name": "example.com.", 263 "created_at": "2014-10-24T19:59:44.000000", 264 "version": 1, 265 "type": "A", 266 "status": "PENDING", 267 "action": "CREATE" 268 } 269 ` 270 271 // CreatedRecordSet is the expected created resource record. 272 var CreatedRecordSet = FirstRecordSet 273 274 // HandleZoneCreationSuccessfully configures the test server to respond to a Create request. 275 func HandleCreateSuccessfully(t *testing.T) { 276 th.Mux.HandleFunc("/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets", 277 func(w http.ResponseWriter, r *http.Request) { 278 th.TestMethod(t, r, "POST") 279 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 280 th.TestJSONRequest(t, r, CreateRecordSetRequest) 281 282 w.WriteHeader(http.StatusCreated) 283 w.Header().Add("Content-Type", "application/json") 284 fmt.Fprintf(w, CreateRecordSetResponse) 285 }) 286 } 287 288 // UpdateRecordSetRequest is a sample request to update a record set. 289 const UpdateRecordSetRequest = ` 290 { 291 "description" : "Updated description", 292 "records" : [ 293 "10.1.0.2", 294 "10.1.0.3" 295 ] 296 } 297 ` 298 299 // UpdateRecordSetResponse is a sample response to an update request. 300 const UpdateRecordSetResponse = ` 301 { 302 "description": "Updated description", 303 "links": { 304 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" 305 }, 306 "updated_at": null, 307 "records": [ 308 "10.1.0.2", 309 "10.1.0.3" 310 ], 311 "ttl": 3600, 312 "id": "f7b10e9b-0cae-4a91-b162-562bc6096648", 313 "name": "example.org.", 314 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 315 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 316 "zone_name": "example.com.", 317 "created_at": "2014-10-24T19:59:44.000000", 318 "version": 2, 319 "type": "A", 320 "status": "PENDING", 321 "action": "UPDATE" 322 } 323 ` 324 325 // HandleUpdateSuccessfully configures the test server to respond to an Update request. 326 func HandleUpdateSuccessfully(t *testing.T) { 327 th.Mux.HandleFunc("/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648", 328 func(w http.ResponseWriter, r *http.Request) { 329 th.TestMethod(t, r, "PUT") 330 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 331 th.TestJSONRequest(t, r, UpdateRecordSetRequest) 332 333 w.WriteHeader(http.StatusOK) 334 w.Header().Add("Content-Type", "application/json") 335 fmt.Fprintf(w, UpdateRecordSetResponse) 336 }) 337 } 338 339 // DeleteRecordSetResponse is a sample response to a delete request. 340 const DeleteRecordSetResponse = ` 341 { 342 "description": "Updated description", 343 "links": { 344 "self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" 345 }, 346 "updated_at": null, 347 "records": [ 348 "10.1.0.2", 349 "10.1.0.3", 350 ], 351 "ttl": null, 352 "id": "f7b10e9b-0cae-4a91-b162-562bc6096648", 353 "name": "example.org.", 354 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 355 "zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", 356 "zone_name": "example.com.", 357 "created_at": "2014-10-24T19:59:44.000000", 358 "version": 2, 359 "type": "A", 360 "status": "PENDING", 361 "action": "UPDATE" 362 } 363 ` 364 365 // HandleDeleteSuccessfully configures the test server to respond to an Delete request. 366 func HandleDeleteSuccessfully(t *testing.T) { 367 th.Mux.HandleFunc("/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648", 368 func(w http.ResponseWriter, r *http.Request) { 369 th.TestMethod(t, r, "DELETE") 370 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 371 372 w.WriteHeader(http.StatusAccepted) 373 //w.Header().Add("Content-Type", "application/json") 374 //fmt.Fprintf(w, DeleteZoneResponse) 375 }) 376 }