OLD | NEW |
| (Empty) |
1 library googleapis.cloudbuild.v1.test; | |
2 | |
3 import "dart:core" as core; | |
4 import "dart:collection" as collection; | |
5 import "dart:async" as async; | |
6 import "dart:convert" as convert; | |
7 | |
8 import 'package:http/http.dart' as http; | |
9 import 'package:http/testing.dart' as http_testing; | |
10 import 'package:unittest/unittest.dart' as unittest; | |
11 | |
12 import 'package:googleapis/cloudbuild/v1.dart' as api; | |
13 | |
14 class HttpServerMock extends http.BaseClient { | |
15 core.Function _callback; | |
16 core.bool _expectJson; | |
17 | |
18 void register(core.Function callback, core.bool expectJson) { | |
19 _callback = callback; | |
20 _expectJson = expectJson; | |
21 } | |
22 | |
23 async.Future<http.StreamedResponse> send(http.BaseRequest request) { | |
24 if (_expectJson) { | |
25 return request.finalize() | |
26 .transform(convert.UTF8.decoder) | |
27 .join('') | |
28 .then((core.String jsonString) { | |
29 if (jsonString.isEmpty) { | |
30 return _callback(request, null); | |
31 } else { | |
32 return _callback(request, convert.JSON.decode(jsonString)); | |
33 } | |
34 }); | |
35 } else { | |
36 var stream = request.finalize(); | |
37 if (stream == null) { | |
38 return _callback(request, []); | |
39 } else { | |
40 return stream.toBytes().then((data) { | |
41 return _callback(request, data); | |
42 }); | |
43 } | |
44 } | |
45 } | |
46 } | |
47 | |
48 http.StreamedResponse stringResponse( | |
49 core.int status, core.Map headers, core.String body) { | |
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | |
51 return new http.StreamedResponse(stream, status, headers: headers); | |
52 } | |
53 | |
54 buildUnnamed630() { | |
55 var o = new core.List<core.String>(); | |
56 o.add("foo"); | |
57 o.add("foo"); | |
58 return o; | |
59 } | |
60 | |
61 checkUnnamed630(core.List<core.String> o) { | |
62 unittest.expect(o, unittest.hasLength(2)); | |
63 unittest.expect(o[0], unittest.equals('foo')); | |
64 unittest.expect(o[1], unittest.equals('foo')); | |
65 } | |
66 | |
67 buildUnnamed631() { | |
68 var o = new core.List<api.BuildStep>(); | |
69 o.add(buildBuildStep()); | |
70 o.add(buildBuildStep()); | |
71 return o; | |
72 } | |
73 | |
74 checkUnnamed631(core.List<api.BuildStep> o) { | |
75 unittest.expect(o, unittest.hasLength(2)); | |
76 checkBuildStep(o[0]); | |
77 checkBuildStep(o[1]); | |
78 } | |
79 | |
80 core.int buildCounterBuild = 0; | |
81 buildBuild() { | |
82 var o = new api.Build(); | |
83 buildCounterBuild++; | |
84 if (buildCounterBuild < 3) { | |
85 o.createTime = "foo"; | |
86 o.finishTime = "foo"; | |
87 o.id = "foo"; | |
88 o.images = buildUnnamed630(); | |
89 o.logsBucket = "foo"; | |
90 o.projectId = "foo"; | |
91 o.results = buildResults(); | |
92 o.source = buildSource(); | |
93 o.startTime = "foo"; | |
94 o.status = "foo"; | |
95 o.statusDetail = "foo"; | |
96 o.steps = buildUnnamed631(); | |
97 o.timeout = "foo"; | |
98 } | |
99 buildCounterBuild--; | |
100 return o; | |
101 } | |
102 | |
103 checkBuild(api.Build o) { | |
104 buildCounterBuild++; | |
105 if (buildCounterBuild < 3) { | |
106 unittest.expect(o.createTime, unittest.equals('foo')); | |
107 unittest.expect(o.finishTime, unittest.equals('foo')); | |
108 unittest.expect(o.id, unittest.equals('foo')); | |
109 checkUnnamed630(o.images); | |
110 unittest.expect(o.logsBucket, unittest.equals('foo')); | |
111 unittest.expect(o.projectId, unittest.equals('foo')); | |
112 checkResults(o.results); | |
113 checkSource(o.source); | |
114 unittest.expect(o.startTime, unittest.equals('foo')); | |
115 unittest.expect(o.status, unittest.equals('foo')); | |
116 unittest.expect(o.statusDetail, unittest.equals('foo')); | |
117 checkUnnamed631(o.steps); | |
118 unittest.expect(o.timeout, unittest.equals('foo')); | |
119 } | |
120 buildCounterBuild--; | |
121 } | |
122 | |
123 core.int buildCounterBuildOperationMetadata = 0; | |
124 buildBuildOperationMetadata() { | |
125 var o = new api.BuildOperationMetadata(); | |
126 buildCounterBuildOperationMetadata++; | |
127 if (buildCounterBuildOperationMetadata < 3) { | |
128 o.build = buildBuild(); | |
129 } | |
130 buildCounterBuildOperationMetadata--; | |
131 return o; | |
132 } | |
133 | |
134 checkBuildOperationMetadata(api.BuildOperationMetadata o) { | |
135 buildCounterBuildOperationMetadata++; | |
136 if (buildCounterBuildOperationMetadata < 3) { | |
137 checkBuild(o.build); | |
138 } | |
139 buildCounterBuildOperationMetadata--; | |
140 } | |
141 | |
142 buildUnnamed632() { | |
143 var o = new core.List<core.String>(); | |
144 o.add("foo"); | |
145 o.add("foo"); | |
146 return o; | |
147 } | |
148 | |
149 checkUnnamed632(core.List<core.String> o) { | |
150 unittest.expect(o, unittest.hasLength(2)); | |
151 unittest.expect(o[0], unittest.equals('foo')); | |
152 unittest.expect(o[1], unittest.equals('foo')); | |
153 } | |
154 | |
155 buildUnnamed633() { | |
156 var o = new core.List<core.String>(); | |
157 o.add("foo"); | |
158 o.add("foo"); | |
159 return o; | |
160 } | |
161 | |
162 checkUnnamed633(core.List<core.String> o) { | |
163 unittest.expect(o, unittest.hasLength(2)); | |
164 unittest.expect(o[0], unittest.equals('foo')); | |
165 unittest.expect(o[1], unittest.equals('foo')); | |
166 } | |
167 | |
168 core.int buildCounterBuildStep = 0; | |
169 buildBuildStep() { | |
170 var o = new api.BuildStep(); | |
171 buildCounterBuildStep++; | |
172 if (buildCounterBuildStep < 3) { | |
173 o.args = buildUnnamed632(); | |
174 o.dir = "foo"; | |
175 o.env = buildUnnamed633(); | |
176 o.name = "foo"; | |
177 } | |
178 buildCounterBuildStep--; | |
179 return o; | |
180 } | |
181 | |
182 checkBuildStep(api.BuildStep o) { | |
183 buildCounterBuildStep++; | |
184 if (buildCounterBuildStep < 3) { | |
185 checkUnnamed632(o.args); | |
186 unittest.expect(o.dir, unittest.equals('foo')); | |
187 checkUnnamed633(o.env); | |
188 unittest.expect(o.name, unittest.equals('foo')); | |
189 } | |
190 buildCounterBuildStep--; | |
191 } | |
192 | |
193 core.int buildCounterBuiltImage = 0; | |
194 buildBuiltImage() { | |
195 var o = new api.BuiltImage(); | |
196 buildCounterBuiltImage++; | |
197 if (buildCounterBuiltImage < 3) { | |
198 o.digest = "foo"; | |
199 o.name = "foo"; | |
200 } | |
201 buildCounterBuiltImage--; | |
202 return o; | |
203 } | |
204 | |
205 checkBuiltImage(api.BuiltImage o) { | |
206 buildCounterBuiltImage++; | |
207 if (buildCounterBuiltImage < 3) { | |
208 unittest.expect(o.digest, unittest.equals('foo')); | |
209 unittest.expect(o.name, unittest.equals('foo')); | |
210 } | |
211 buildCounterBuiltImage--; | |
212 } | |
213 | |
214 core.int buildCounterCancelBuildRequest = 0; | |
215 buildCancelBuildRequest() { | |
216 var o = new api.CancelBuildRequest(); | |
217 buildCounterCancelBuildRequest++; | |
218 if (buildCounterCancelBuildRequest < 3) { | |
219 } | |
220 buildCounterCancelBuildRequest--; | |
221 return o; | |
222 } | |
223 | |
224 checkCancelBuildRequest(api.CancelBuildRequest o) { | |
225 buildCounterCancelBuildRequest++; | |
226 if (buildCounterCancelBuildRequest < 3) { | |
227 } | |
228 buildCounterCancelBuildRequest--; | |
229 } | |
230 | |
231 buildUnnamed634() { | |
232 var o = new core.List<api.Build>(); | |
233 o.add(buildBuild()); | |
234 o.add(buildBuild()); | |
235 return o; | |
236 } | |
237 | |
238 checkUnnamed634(core.List<api.Build> o) { | |
239 unittest.expect(o, unittest.hasLength(2)); | |
240 checkBuild(o[0]); | |
241 checkBuild(o[1]); | |
242 } | |
243 | |
244 core.int buildCounterListBuildsResponse = 0; | |
245 buildListBuildsResponse() { | |
246 var o = new api.ListBuildsResponse(); | |
247 buildCounterListBuildsResponse++; | |
248 if (buildCounterListBuildsResponse < 3) { | |
249 o.builds = buildUnnamed634(); | |
250 o.nextPageToken = "foo"; | |
251 } | |
252 buildCounterListBuildsResponse--; | |
253 return o; | |
254 } | |
255 | |
256 checkListBuildsResponse(api.ListBuildsResponse o) { | |
257 buildCounterListBuildsResponse++; | |
258 if (buildCounterListBuildsResponse < 3) { | |
259 checkUnnamed634(o.builds); | |
260 unittest.expect(o.nextPageToken, unittest.equals('foo')); | |
261 } | |
262 buildCounterListBuildsResponse--; | |
263 } | |
264 | |
265 buildUnnamed635() { | |
266 var o = new core.List<api.Operation>(); | |
267 o.add(buildOperation()); | |
268 o.add(buildOperation()); | |
269 return o; | |
270 } | |
271 | |
272 checkUnnamed635(core.List<api.Operation> o) { | |
273 unittest.expect(o, unittest.hasLength(2)); | |
274 checkOperation(o[0]); | |
275 checkOperation(o[1]); | |
276 } | |
277 | |
278 core.int buildCounterListOperationsResponse = 0; | |
279 buildListOperationsResponse() { | |
280 var o = new api.ListOperationsResponse(); | |
281 buildCounterListOperationsResponse++; | |
282 if (buildCounterListOperationsResponse < 3) { | |
283 o.nextPageToken = "foo"; | |
284 o.operations = buildUnnamed635(); | |
285 } | |
286 buildCounterListOperationsResponse--; | |
287 return o; | |
288 } | |
289 | |
290 checkListOperationsResponse(api.ListOperationsResponse o) { | |
291 buildCounterListOperationsResponse++; | |
292 if (buildCounterListOperationsResponse < 3) { | |
293 unittest.expect(o.nextPageToken, unittest.equals('foo')); | |
294 checkUnnamed635(o.operations); | |
295 } | |
296 buildCounterListOperationsResponse--; | |
297 } | |
298 | |
299 buildUnnamed636() { | |
300 var o = new core.Map<core.String, core.Object>(); | |
301 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | |
302 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | |
303 return o; | |
304 } | |
305 | |
306 checkUnnamed636(core.Map<core.String, core.Object> o) { | |
307 unittest.expect(o, unittest.hasLength(2)); | |
308 var casted1 = (o["x"]) as core.Map; unittest.expect(casted1, unittest.hasLengt
h(3)); unittest.expect(casted1["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted1["bool"], unittest.equals(true)); unittest.expect(casted1["string"],
unittest.equals('foo')); | |
309 var casted2 = (o["y"]) as core.Map; unittest.expect(casted2, unittest.hasLengt
h(3)); unittest.expect(casted2["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted2["bool"], unittest.equals(true)); unittest.expect(casted2["string"],
unittest.equals('foo')); | |
310 } | |
311 | |
312 buildUnnamed637() { | |
313 var o = new core.Map<core.String, core.Object>(); | |
314 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | |
315 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | |
316 return o; | |
317 } | |
318 | |
319 checkUnnamed637(core.Map<core.String, core.Object> o) { | |
320 unittest.expect(o, unittest.hasLength(2)); | |
321 var casted3 = (o["x"]) as core.Map; unittest.expect(casted3, unittest.hasLengt
h(3)); unittest.expect(casted3["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted3["bool"], unittest.equals(true)); unittest.expect(casted3["string"],
unittest.equals('foo')); | |
322 var casted4 = (o["y"]) as core.Map; unittest.expect(casted4, unittest.hasLengt
h(3)); unittest.expect(casted4["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted4["bool"], unittest.equals(true)); unittest.expect(casted4["string"],
unittest.equals('foo')); | |
323 } | |
324 | |
325 core.int buildCounterOperation = 0; | |
326 buildOperation() { | |
327 var o = new api.Operation(); | |
328 buildCounterOperation++; | |
329 if (buildCounterOperation < 3) { | |
330 o.done = true; | |
331 o.error = buildStatus(); | |
332 o.metadata = buildUnnamed636(); | |
333 o.name = "foo"; | |
334 o.response = buildUnnamed637(); | |
335 } | |
336 buildCounterOperation--; | |
337 return o; | |
338 } | |
339 | |
340 checkOperation(api.Operation o) { | |
341 buildCounterOperation++; | |
342 if (buildCounterOperation < 3) { | |
343 unittest.expect(o.done, unittest.isTrue); | |
344 checkStatus(o.error); | |
345 checkUnnamed636(o.metadata); | |
346 unittest.expect(o.name, unittest.equals('foo')); | |
347 checkUnnamed637(o.response); | |
348 } | |
349 buildCounterOperation--; | |
350 } | |
351 | |
352 buildUnnamed638() { | |
353 var o = new core.List<api.BuiltImage>(); | |
354 o.add(buildBuiltImage()); | |
355 o.add(buildBuiltImage()); | |
356 return o; | |
357 } | |
358 | |
359 checkUnnamed638(core.List<api.BuiltImage> o) { | |
360 unittest.expect(o, unittest.hasLength(2)); | |
361 checkBuiltImage(o[0]); | |
362 checkBuiltImage(o[1]); | |
363 } | |
364 | |
365 core.int buildCounterResults = 0; | |
366 buildResults() { | |
367 var o = new api.Results(); | |
368 buildCounterResults++; | |
369 if (buildCounterResults < 3) { | |
370 o.images = buildUnnamed638(); | |
371 } | |
372 buildCounterResults--; | |
373 return o; | |
374 } | |
375 | |
376 checkResults(api.Results o) { | |
377 buildCounterResults++; | |
378 if (buildCounterResults < 3) { | |
379 checkUnnamed638(o.images); | |
380 } | |
381 buildCounterResults--; | |
382 } | |
383 | |
384 core.int buildCounterSource = 0; | |
385 buildSource() { | |
386 var o = new api.Source(); | |
387 buildCounterSource++; | |
388 if (buildCounterSource < 3) { | |
389 o.storageSource = buildStorageSource(); | |
390 } | |
391 buildCounterSource--; | |
392 return o; | |
393 } | |
394 | |
395 checkSource(api.Source o) { | |
396 buildCounterSource++; | |
397 if (buildCounterSource < 3) { | |
398 checkStorageSource(o.storageSource); | |
399 } | |
400 buildCounterSource--; | |
401 } | |
402 | |
403 buildUnnamed639() { | |
404 var o = new core.Map<core.String, core.Object>(); | |
405 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | |
406 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | |
407 return o; | |
408 } | |
409 | |
410 checkUnnamed639(core.Map<core.String, core.Object> o) { | |
411 unittest.expect(o, unittest.hasLength(2)); | |
412 var casted5 = (o["x"]) as core.Map; unittest.expect(casted5, unittest.hasLengt
h(3)); unittest.expect(casted5["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted5["bool"], unittest.equals(true)); unittest.expect(casted5["string"],
unittest.equals('foo')); | |
413 var casted6 = (o["y"]) as core.Map; unittest.expect(casted6, unittest.hasLengt
h(3)); unittest.expect(casted6["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted6["bool"], unittest.equals(true)); unittest.expect(casted6["string"],
unittest.equals('foo')); | |
414 } | |
415 | |
416 buildUnnamed640() { | |
417 var o = new core.List<core.Map<core.String, core.Object>>(); | |
418 o.add(buildUnnamed639()); | |
419 o.add(buildUnnamed639()); | |
420 return o; | |
421 } | |
422 | |
423 checkUnnamed640(core.List<core.Map<core.String, core.Object>> o) { | |
424 unittest.expect(o, unittest.hasLength(2)); | |
425 checkUnnamed639(o[0]); | |
426 checkUnnamed639(o[1]); | |
427 } | |
428 | |
429 core.int buildCounterStatus = 0; | |
430 buildStatus() { | |
431 var o = new api.Status(); | |
432 buildCounterStatus++; | |
433 if (buildCounterStatus < 3) { | |
434 o.code = 42; | |
435 o.details = buildUnnamed640(); | |
436 o.message = "foo"; | |
437 } | |
438 buildCounterStatus--; | |
439 return o; | |
440 } | |
441 | |
442 checkStatus(api.Status o) { | |
443 buildCounterStatus++; | |
444 if (buildCounterStatus < 3) { | |
445 unittest.expect(o.code, unittest.equals(42)); | |
446 checkUnnamed640(o.details); | |
447 unittest.expect(o.message, unittest.equals('foo')); | |
448 } | |
449 buildCounterStatus--; | |
450 } | |
451 | |
452 core.int buildCounterStorageSource = 0; | |
453 buildStorageSource() { | |
454 var o = new api.StorageSource(); | |
455 buildCounterStorageSource++; | |
456 if (buildCounterStorageSource < 3) { | |
457 o.bucket = "foo"; | |
458 o.generation = "foo"; | |
459 o.object = "foo"; | |
460 } | |
461 buildCounterStorageSource--; | |
462 return o; | |
463 } | |
464 | |
465 checkStorageSource(api.StorageSource o) { | |
466 buildCounterStorageSource++; | |
467 if (buildCounterStorageSource < 3) { | |
468 unittest.expect(o.bucket, unittest.equals('foo')); | |
469 unittest.expect(o.generation, unittest.equals('foo')); | |
470 unittest.expect(o.object, unittest.equals('foo')); | |
471 } | |
472 buildCounterStorageSource--; | |
473 } | |
474 | |
475 | |
476 main() { | |
477 unittest.group("obj-schema-Build", () { | |
478 unittest.test("to-json--from-json", () { | |
479 var o = buildBuild(); | |
480 var od = new api.Build.fromJson(o.toJson()); | |
481 checkBuild(od); | |
482 }); | |
483 }); | |
484 | |
485 | |
486 unittest.group("obj-schema-BuildOperationMetadata", () { | |
487 unittest.test("to-json--from-json", () { | |
488 var o = buildBuildOperationMetadata(); | |
489 var od = new api.BuildOperationMetadata.fromJson(o.toJson()); | |
490 checkBuildOperationMetadata(od); | |
491 }); | |
492 }); | |
493 | |
494 | |
495 unittest.group("obj-schema-BuildStep", () { | |
496 unittest.test("to-json--from-json", () { | |
497 var o = buildBuildStep(); | |
498 var od = new api.BuildStep.fromJson(o.toJson()); | |
499 checkBuildStep(od); | |
500 }); | |
501 }); | |
502 | |
503 | |
504 unittest.group("obj-schema-BuiltImage", () { | |
505 unittest.test("to-json--from-json", () { | |
506 var o = buildBuiltImage(); | |
507 var od = new api.BuiltImage.fromJson(o.toJson()); | |
508 checkBuiltImage(od); | |
509 }); | |
510 }); | |
511 | |
512 | |
513 unittest.group("obj-schema-CancelBuildRequest", () { | |
514 unittest.test("to-json--from-json", () { | |
515 var o = buildCancelBuildRequest(); | |
516 var od = new api.CancelBuildRequest.fromJson(o.toJson()); | |
517 checkCancelBuildRequest(od); | |
518 }); | |
519 }); | |
520 | |
521 | |
522 unittest.group("obj-schema-ListBuildsResponse", () { | |
523 unittest.test("to-json--from-json", () { | |
524 var o = buildListBuildsResponse(); | |
525 var od = new api.ListBuildsResponse.fromJson(o.toJson()); | |
526 checkListBuildsResponse(od); | |
527 }); | |
528 }); | |
529 | |
530 | |
531 unittest.group("obj-schema-ListOperationsResponse", () { | |
532 unittest.test("to-json--from-json", () { | |
533 var o = buildListOperationsResponse(); | |
534 var od = new api.ListOperationsResponse.fromJson(o.toJson()); | |
535 checkListOperationsResponse(od); | |
536 }); | |
537 }); | |
538 | |
539 | |
540 unittest.group("obj-schema-Operation", () { | |
541 unittest.test("to-json--from-json", () { | |
542 var o = buildOperation(); | |
543 var od = new api.Operation.fromJson(o.toJson()); | |
544 checkOperation(od); | |
545 }); | |
546 }); | |
547 | |
548 | |
549 unittest.group("obj-schema-Results", () { | |
550 unittest.test("to-json--from-json", () { | |
551 var o = buildResults(); | |
552 var od = new api.Results.fromJson(o.toJson()); | |
553 checkResults(od); | |
554 }); | |
555 }); | |
556 | |
557 | |
558 unittest.group("obj-schema-Source", () { | |
559 unittest.test("to-json--from-json", () { | |
560 var o = buildSource(); | |
561 var od = new api.Source.fromJson(o.toJson()); | |
562 checkSource(od); | |
563 }); | |
564 }); | |
565 | |
566 | |
567 unittest.group("obj-schema-Status", () { | |
568 unittest.test("to-json--from-json", () { | |
569 var o = buildStatus(); | |
570 var od = new api.Status.fromJson(o.toJson()); | |
571 checkStatus(od); | |
572 }); | |
573 }); | |
574 | |
575 | |
576 unittest.group("obj-schema-StorageSource", () { | |
577 unittest.test("to-json--from-json", () { | |
578 var o = buildStorageSource(); | |
579 var od = new api.StorageSource.fromJson(o.toJson()); | |
580 checkStorageSource(od); | |
581 }); | |
582 }); | |
583 | |
584 | |
585 unittest.group("resource-OperationsResourceApi", () { | |
586 unittest.test("method--get", () { | |
587 | |
588 var mock = new HttpServerMock(); | |
589 api.OperationsResourceApi res = new api.CloudbuildApi(mock).operations; | |
590 var arg_name = "foo"; | |
591 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
592 var path = (req.url).path; | |
593 var pathOffset = 0; | |
594 var index; | |
595 var subPart; | |
596 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
597 pathOffset += 1; | |
598 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); | |
599 pathOffset += 3; | |
600 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | |
601 | |
602 var query = (req.url).query; | |
603 var queryOffset = 0; | |
604 var queryMap = {}; | |
605 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
606 parseBool(n) { | |
607 if (n == "true") return true; | |
608 if (n == "false") return false; | |
609 if (n == null) return null; | |
610 throw new core.ArgumentError("Invalid boolean: $n"); | |
611 } | |
612 if (query.length > 0) { | |
613 for (var part in query.split("&")) { | |
614 var keyvalue = part.split("="); | |
615 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
616 } | |
617 } | |
618 | |
619 | |
620 var h = { | |
621 "content-type" : "application/json; charset=utf-8", | |
622 }; | |
623 var resp = convert.JSON.encode(buildOperation()); | |
624 return new async.Future.value(stringResponse(200, h, resp)); | |
625 }), true); | |
626 res.get(arg_name).then(unittest.expectAsync(((api.Operation response) { | |
627 checkOperation(response); | |
628 }))); | |
629 }); | |
630 | |
631 unittest.test("method--list", () { | |
632 | |
633 var mock = new HttpServerMock(); | |
634 api.OperationsResourceApi res = new api.CloudbuildApi(mock).operations; | |
635 var arg_name = "foo"; | |
636 var arg_pageSize = 42; | |
637 var arg_filter = "foo"; | |
638 var arg_pageToken = "foo"; | |
639 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
640 var path = (req.url).path; | |
641 var pathOffset = 0; | |
642 var index; | |
643 var subPart; | |
644 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
645 pathOffset += 1; | |
646 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); | |
647 pathOffset += 3; | |
648 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | |
649 | |
650 var query = (req.url).query; | |
651 var queryOffset = 0; | |
652 var queryMap = {}; | |
653 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
654 parseBool(n) { | |
655 if (n == "true") return true; | |
656 if (n == "false") return false; | |
657 if (n == null) return null; | |
658 throw new core.ArgumentError("Invalid boolean: $n"); | |
659 } | |
660 if (query.length > 0) { | |
661 for (var part in query.split("&")) { | |
662 var keyvalue = part.split("="); | |
663 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
664 } | |
665 } | |
666 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); | |
667 unittest.expect(queryMap["filter"].first, unittest.equals(arg_filter)); | |
668 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); | |
669 | |
670 | |
671 var h = { | |
672 "content-type" : "application/json; charset=utf-8", | |
673 }; | |
674 var resp = convert.JSON.encode(buildListOperationsResponse()); | |
675 return new async.Future.value(stringResponse(200, h, resp)); | |
676 }), true); | |
677 res.list(arg_name, pageSize: arg_pageSize, filter: arg_filter, pageToken:
arg_pageToken).then(unittest.expectAsync(((api.ListOperationsResponse response)
{ | |
678 checkListOperationsResponse(response); | |
679 }))); | |
680 }); | |
681 | |
682 }); | |
683 | |
684 | |
685 unittest.group("resource-ProjectsBuildsResourceApi", () { | |
686 unittest.test("method--cancel", () { | |
687 | |
688 var mock = new HttpServerMock(); | |
689 api.ProjectsBuildsResourceApi res = new api.CloudbuildApi(mock).projects.b
uilds; | |
690 var arg_request = buildCancelBuildRequest(); | |
691 var arg_projectId = "foo"; | |
692 var arg_id = "foo"; | |
693 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
694 var obj = new api.CancelBuildRequest.fromJson(json); | |
695 checkCancelBuildRequest(obj); | |
696 | |
697 var path = (req.url).path; | |
698 var pathOffset = 0; | |
699 var index; | |
700 var subPart; | |
701 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
702 pathOffset += 1; | |
703 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); | |
704 pathOffset += 12; | |
705 index = path.indexOf("/builds/", pathOffset); | |
706 unittest.expect(index >= 0, unittest.isTrue); | |
707 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); | |
708 pathOffset = index; | |
709 unittest.expect(subPart, unittest.equals("$arg_projectId")); | |
710 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ
als("/builds/")); | |
711 pathOffset += 8; | |
712 index = path.indexOf(":cancel", pathOffset); | |
713 unittest.expect(index >= 0, unittest.isTrue); | |
714 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); | |
715 pathOffset = index; | |
716 unittest.expect(subPart, unittest.equals("$arg_id")); | |
717 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als(":cancel")); | |
718 pathOffset += 7; | |
719 | |
720 var query = (req.url).query; | |
721 var queryOffset = 0; | |
722 var queryMap = {}; | |
723 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
724 parseBool(n) { | |
725 if (n == "true") return true; | |
726 if (n == "false") return false; | |
727 if (n == null) return null; | |
728 throw new core.ArgumentError("Invalid boolean: $n"); | |
729 } | |
730 if (query.length > 0) { | |
731 for (var part in query.split("&")) { | |
732 var keyvalue = part.split("="); | |
733 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
734 } | |
735 } | |
736 | |
737 | |
738 var h = { | |
739 "content-type" : "application/json; charset=utf-8", | |
740 }; | |
741 var resp = convert.JSON.encode(buildBuild()); | |
742 return new async.Future.value(stringResponse(200, h, resp)); | |
743 }), true); | |
744 res.cancel(arg_request, arg_projectId, arg_id).then(unittest.expectAsync((
(api.Build response) { | |
745 checkBuild(response); | |
746 }))); | |
747 }); | |
748 | |
749 unittest.test("method--create", () { | |
750 | |
751 var mock = new HttpServerMock(); | |
752 api.ProjectsBuildsResourceApi res = new api.CloudbuildApi(mock).projects.b
uilds; | |
753 var arg_request = buildBuild(); | |
754 var arg_projectId = "foo"; | |
755 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
756 var obj = new api.Build.fromJson(json); | |
757 checkBuild(obj); | |
758 | |
759 var path = (req.url).path; | |
760 var pathOffset = 0; | |
761 var index; | |
762 var subPart; | |
763 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
764 pathOffset += 1; | |
765 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); | |
766 pathOffset += 12; | |
767 index = path.indexOf("/builds", pathOffset); | |
768 unittest.expect(index >= 0, unittest.isTrue); | |
769 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); | |
770 pathOffset = index; | |
771 unittest.expect(subPart, unittest.equals("$arg_projectId")); | |
772 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("/builds")); | |
773 pathOffset += 7; | |
774 | |
775 var query = (req.url).query; | |
776 var queryOffset = 0; | |
777 var queryMap = {}; | |
778 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
779 parseBool(n) { | |
780 if (n == "true") return true; | |
781 if (n == "false") return false; | |
782 if (n == null) return null; | |
783 throw new core.ArgumentError("Invalid boolean: $n"); | |
784 } | |
785 if (query.length > 0) { | |
786 for (var part in query.split("&")) { | |
787 var keyvalue = part.split("="); | |
788 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
789 } | |
790 } | |
791 | |
792 | |
793 var h = { | |
794 "content-type" : "application/json; charset=utf-8", | |
795 }; | |
796 var resp = convert.JSON.encode(buildOperation()); | |
797 return new async.Future.value(stringResponse(200, h, resp)); | |
798 }), true); | |
799 res.create(arg_request, arg_projectId).then(unittest.expectAsync(((api.Ope
ration response) { | |
800 checkOperation(response); | |
801 }))); | |
802 }); | |
803 | |
804 unittest.test("method--get", () { | |
805 | |
806 var mock = new HttpServerMock(); | |
807 api.ProjectsBuildsResourceApi res = new api.CloudbuildApi(mock).projects.b
uilds; | |
808 var arg_projectId = "foo"; | |
809 var arg_id = "foo"; | |
810 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
811 var path = (req.url).path; | |
812 var pathOffset = 0; | |
813 var index; | |
814 var subPart; | |
815 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
816 pathOffset += 1; | |
817 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); | |
818 pathOffset += 12; | |
819 index = path.indexOf("/builds/", pathOffset); | |
820 unittest.expect(index >= 0, unittest.isTrue); | |
821 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); | |
822 pathOffset = index; | |
823 unittest.expect(subPart, unittest.equals("$arg_projectId")); | |
824 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ
als("/builds/")); | |
825 pathOffset += 8; | |
826 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset)); | |
827 pathOffset = path.length; | |
828 unittest.expect(subPart, unittest.equals("$arg_id")); | |
829 | |
830 var query = (req.url).query; | |
831 var queryOffset = 0; | |
832 var queryMap = {}; | |
833 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
834 parseBool(n) { | |
835 if (n == "true") return true; | |
836 if (n == "false") return false; | |
837 if (n == null) return null; | |
838 throw new core.ArgumentError("Invalid boolean: $n"); | |
839 } | |
840 if (query.length > 0) { | |
841 for (var part in query.split("&")) { | |
842 var keyvalue = part.split("="); | |
843 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
844 } | |
845 } | |
846 | |
847 | |
848 var h = { | |
849 "content-type" : "application/json; charset=utf-8", | |
850 }; | |
851 var resp = convert.JSON.encode(buildBuild()); | |
852 return new async.Future.value(stringResponse(200, h, resp)); | |
853 }), true); | |
854 res.get(arg_projectId, arg_id).then(unittest.expectAsync(((api.Build respo
nse) { | |
855 checkBuild(response); | |
856 }))); | |
857 }); | |
858 | |
859 unittest.test("method--list", () { | |
860 | |
861 var mock = new HttpServerMock(); | |
862 api.ProjectsBuildsResourceApi res = new api.CloudbuildApi(mock).projects.b
uilds; | |
863 var arg_projectId = "foo"; | |
864 var arg_pageSize = 42; | |
865 var arg_pageToken = "foo"; | |
866 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
867 var path = (req.url).path; | |
868 var pathOffset = 0; | |
869 var index; | |
870 var subPart; | |
871 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
872 pathOffset += 1; | |
873 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); | |
874 pathOffset += 12; | |
875 index = path.indexOf("/builds", pathOffset); | |
876 unittest.expect(index >= 0, unittest.isTrue); | |
877 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); | |
878 pathOffset = index; | |
879 unittest.expect(subPart, unittest.equals("$arg_projectId")); | |
880 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("/builds")); | |
881 pathOffset += 7; | |
882 | |
883 var query = (req.url).query; | |
884 var queryOffset = 0; | |
885 var queryMap = {}; | |
886 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
887 parseBool(n) { | |
888 if (n == "true") return true; | |
889 if (n == "false") return false; | |
890 if (n == null) return null; | |
891 throw new core.ArgumentError("Invalid boolean: $n"); | |
892 } | |
893 if (query.length > 0) { | |
894 for (var part in query.split("&")) { | |
895 var keyvalue = part.split("="); | |
896 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
897 } | |
898 } | |
899 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); | |
900 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); | |
901 | |
902 | |
903 var h = { | |
904 "content-type" : "application/json; charset=utf-8", | |
905 }; | |
906 var resp = convert.JSON.encode(buildListBuildsResponse()); | |
907 return new async.Future.value(stringResponse(200, h, resp)); | |
908 }), true); | |
909 res.list(arg_projectId, pageSize: arg_pageSize, pageToken: arg_pageToken).
then(unittest.expectAsync(((api.ListBuildsResponse response) { | |
910 checkListBuildsResponse(response); | |
911 }))); | |
912 }); | |
913 | |
914 }); | |
915 | |
916 | |
917 } | |
918 | |
OLD | NEW |