OLD | NEW |
(Empty) | |
| 1 library googleapis.cloudfunctions.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/cloudfunctions/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 buildUnnamed97() { |
| 55 var o = new core.Map<core.String, core.String>(); |
| 56 o["x"] = "foo"; |
| 57 o["y"] = "foo"; |
| 58 return o; |
| 59 } |
| 60 |
| 61 checkUnnamed97(core.Map<core.String, core.String> o) { |
| 62 unittest.expect(o, unittest.hasLength(2)); |
| 63 unittest.expect(o["x"], unittest.equals('foo')); |
| 64 unittest.expect(o["y"], unittest.equals('foo')); |
| 65 } |
| 66 |
| 67 buildUnnamed98() { |
| 68 var o = new core.Map<core.String, core.Object>(); |
| 69 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 70 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 71 return o; |
| 72 } |
| 73 |
| 74 checkUnnamed98(core.Map<core.String, core.Object> o) { |
| 75 unittest.expect(o, unittest.hasLength(2)); |
| 76 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')); |
| 77 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')); |
| 78 } |
| 79 |
| 80 core.int buildCounterLocation = 0; |
| 81 buildLocation() { |
| 82 var o = new api.Location(); |
| 83 buildCounterLocation++; |
| 84 if (buildCounterLocation < 3) { |
| 85 o.labels = buildUnnamed97(); |
| 86 o.locationId = "foo"; |
| 87 o.metadata = buildUnnamed98(); |
| 88 o.name = "foo"; |
| 89 } |
| 90 buildCounterLocation--; |
| 91 return o; |
| 92 } |
| 93 |
| 94 checkLocation(api.Location o) { |
| 95 buildCounterLocation++; |
| 96 if (buildCounterLocation < 3) { |
| 97 checkUnnamed97(o.labels); |
| 98 unittest.expect(o.locationId, unittest.equals('foo')); |
| 99 checkUnnamed98(o.metadata); |
| 100 unittest.expect(o.name, unittest.equals('foo')); |
| 101 } |
| 102 buildCounterLocation--; |
| 103 } |
| 104 |
| 105 buildUnnamed99() { |
| 106 var o = new core.Map<core.String, core.Object>(); |
| 107 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 108 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 109 return o; |
| 110 } |
| 111 |
| 112 checkUnnamed99(core.Map<core.String, core.Object> o) { |
| 113 unittest.expect(o, unittest.hasLength(2)); |
| 114 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')); |
| 115 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')); |
| 116 } |
| 117 |
| 118 core.int buildCounterOperationMetadataV1Beta2 = 0; |
| 119 buildOperationMetadataV1Beta2() { |
| 120 var o = new api.OperationMetadataV1Beta2(); |
| 121 buildCounterOperationMetadataV1Beta2++; |
| 122 if (buildCounterOperationMetadataV1Beta2 < 3) { |
| 123 o.request = buildUnnamed99(); |
| 124 o.target = "foo"; |
| 125 o.type = "foo"; |
| 126 } |
| 127 buildCounterOperationMetadataV1Beta2--; |
| 128 return o; |
| 129 } |
| 130 |
| 131 checkOperationMetadataV1Beta2(api.OperationMetadataV1Beta2 o) { |
| 132 buildCounterOperationMetadataV1Beta2++; |
| 133 if (buildCounterOperationMetadataV1Beta2 < 3) { |
| 134 checkUnnamed99(o.request); |
| 135 unittest.expect(o.target, unittest.equals('foo')); |
| 136 unittest.expect(o.type, unittest.equals('foo')); |
| 137 } |
| 138 buildCounterOperationMetadataV1Beta2--; |
| 139 } |
| 140 |
| 141 |
| 142 main() { |
| 143 unittest.group("obj-schema-Location", () { |
| 144 unittest.test("to-json--from-json", () { |
| 145 var o = buildLocation(); |
| 146 var od = new api.Location.fromJson(o.toJson()); |
| 147 checkLocation(od); |
| 148 }); |
| 149 }); |
| 150 |
| 151 |
| 152 unittest.group("obj-schema-OperationMetadataV1Beta2", () { |
| 153 unittest.test("to-json--from-json", () { |
| 154 var o = buildOperationMetadataV1Beta2(); |
| 155 var od = new api.OperationMetadataV1Beta2.fromJson(o.toJson()); |
| 156 checkOperationMetadataV1Beta2(od); |
| 157 }); |
| 158 }); |
| 159 |
| 160 |
| 161 unittest.group("resource-ProjectsLocationsResourceApi", () { |
| 162 unittest.test("method--get", () { |
| 163 |
| 164 var mock = new HttpServerMock(); |
| 165 api.ProjectsLocationsResourceApi res = new api.CloudfunctionsApi(mock).pro
jects.locations; |
| 166 var arg_name = "foo"; |
| 167 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 168 var path = (req.url).path; |
| 169 var pathOffset = 0; |
| 170 var index; |
| 171 var subPart; |
| 172 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 173 pathOffset += 1; |
| 174 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 175 pathOffset += 3; |
| 176 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 177 |
| 178 var query = (req.url).query; |
| 179 var queryOffset = 0; |
| 180 var queryMap = {}; |
| 181 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 182 parseBool(n) { |
| 183 if (n == "true") return true; |
| 184 if (n == "false") return false; |
| 185 if (n == null) return null; |
| 186 throw new core.ArgumentError("Invalid boolean: $n"); |
| 187 } |
| 188 if (query.length > 0) { |
| 189 for (var part in query.split("&")) { |
| 190 var keyvalue = part.split("="); |
| 191 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 192 } |
| 193 } |
| 194 |
| 195 |
| 196 var h = { |
| 197 "content-type" : "application/json; charset=utf-8", |
| 198 }; |
| 199 var resp = convert.JSON.encode(buildLocation()); |
| 200 return new async.Future.value(stringResponse(200, h, resp)); |
| 201 }), true); |
| 202 res.get(arg_name).then(unittest.expectAsync(((api.Location response) { |
| 203 checkLocation(response); |
| 204 }))); |
| 205 }); |
| 206 |
| 207 }); |
| 208 |
| 209 |
| 210 } |
| 211 |
OLD | NEW |