OLD | NEW |
1 library googleapis.cloudfunctions.v1.test; | 1 library googleapis.cloudfunctions.v1.test; |
2 | 2 |
3 import "dart:core" as core; | 3 import "dart:core" as core; |
4 import "dart:collection" as collection; | 4 import "dart:collection" as collection; |
5 import "dart:async" as async; | 5 import "dart:async" as async; |
6 import "dart:convert" as convert; | 6 import "dart:convert" as convert; |
7 | 7 |
8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
9 import 'package:http/testing.dart' as http_testing; | 9 import 'package:http/testing.dart' as http_testing; |
10 import 'package:unittest/unittest.dart' as unittest; | 10 import 'package:unittest/unittest.dart' as unittest; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 http.StreamedResponse stringResponse( | 48 http.StreamedResponse stringResponse( |
49 core.int status, core.Map headers, core.String body) { | 49 core.int status, core.Map headers, core.String body) { |
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
51 return new http.StreamedResponse(stream, status, headers: headers); | 51 return new http.StreamedResponse(stream, status, headers: headers); |
52 } | 52 } |
53 | 53 |
54 buildUnnamed97() { | 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>(); | 55 var o = new core.Map<core.String, core.Object>(); |
69 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | 56 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
70 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; | 57 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
71 return o; | 58 return o; |
72 } | 59 } |
73 | 60 |
74 checkUnnamed98(core.Map<core.String, core.Object> o) { | 61 checkUnnamed97(core.Map<core.String, core.Object> o) { |
75 unittest.expect(o, unittest.hasLength(2)); | 62 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')); | 63 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')); | 64 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 } | 65 } |
79 | 66 |
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; | 67 core.int buildCounterOperationMetadataV1Beta2 = 0; |
119 buildOperationMetadataV1Beta2() { | 68 buildOperationMetadataV1Beta2() { |
120 var o = new api.OperationMetadataV1Beta2(); | 69 var o = new api.OperationMetadataV1Beta2(); |
121 buildCounterOperationMetadataV1Beta2++; | 70 buildCounterOperationMetadataV1Beta2++; |
122 if (buildCounterOperationMetadataV1Beta2 < 3) { | 71 if (buildCounterOperationMetadataV1Beta2 < 3) { |
123 o.request = buildUnnamed99(); | 72 o.request = buildUnnamed97(); |
124 o.target = "foo"; | 73 o.target = "foo"; |
125 o.type = "foo"; | 74 o.type = "foo"; |
126 } | 75 } |
127 buildCounterOperationMetadataV1Beta2--; | 76 buildCounterOperationMetadataV1Beta2--; |
128 return o; | 77 return o; |
129 } | 78 } |
130 | 79 |
131 checkOperationMetadataV1Beta2(api.OperationMetadataV1Beta2 o) { | 80 checkOperationMetadataV1Beta2(api.OperationMetadataV1Beta2 o) { |
132 buildCounterOperationMetadataV1Beta2++; | 81 buildCounterOperationMetadataV1Beta2++; |
133 if (buildCounterOperationMetadataV1Beta2 < 3) { | 82 if (buildCounterOperationMetadataV1Beta2 < 3) { |
134 checkUnnamed99(o.request); | 83 checkUnnamed97(o.request); |
135 unittest.expect(o.target, unittest.equals('foo')); | 84 unittest.expect(o.target, unittest.equals('foo')); |
136 unittest.expect(o.type, unittest.equals('foo')); | 85 unittest.expect(o.type, unittest.equals('foo')); |
137 } | 86 } |
138 buildCounterOperationMetadataV1Beta2--; | 87 buildCounterOperationMetadataV1Beta2--; |
139 } | 88 } |
140 | 89 |
141 | 90 |
142 main() { | 91 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", () { | 92 unittest.group("obj-schema-OperationMetadataV1Beta2", () { |
153 unittest.test("to-json--from-json", () { | 93 unittest.test("to-json--from-json", () { |
154 var o = buildOperationMetadataV1Beta2(); | 94 var o = buildOperationMetadataV1Beta2(); |
155 var od = new api.OperationMetadataV1Beta2.fromJson(o.toJson()); | 95 var od = new api.OperationMetadataV1Beta2.fromJson(o.toJson()); |
156 checkOperationMetadataV1Beta2(od); | 96 checkOperationMetadataV1Beta2(od); |
157 }); | 97 }); |
158 }); | 98 }); |
159 | 99 |
160 | 100 |
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 } | 101 } |
211 | 102 |
OLD | NEW |