blob: 527c3f0fec1563fc1594c97f4aa3b43adc8c24a9 [file] [log] [blame]
library googleapis.cloudprofiler.v2.test;
import "dart:core" as core;
import "dart:async" as async;
import "dart:convert" as convert;
import 'package:http/http.dart' as http;
import 'package:test/test.dart' as unittest;
import 'package:googleapis/cloudprofiler/v2.dart' as api;
class HttpServerMock extends http.BaseClient {
core.Function _callback;
core.bool _expectJson;
void register(core.Function callback, core.bool expectJson) {
_callback = callback;
_expectJson = expectJson;
}
async.Future<http.StreamedResponse> send(http.BaseRequest request) {
if (_expectJson) {
return request
.finalize()
.transform(convert.utf8.decoder)
.join('')
.then((core.String jsonString) {
if (jsonString.isEmpty) {
return _callback(request, null);
} else {
return _callback(request, convert.json.decode(jsonString));
}
});
} else {
var stream = request.finalize();
if (stream == null) {
return _callback(request, []);
} else {
return stream.toBytes().then((data) {
return _callback(request, data);
});
}
}
}
}
http.StreamedResponse stringResponse(core.int status,
core.Map<core.String, core.String> headers, core.String body) {
var stream = new async.Stream.fromIterable([convert.utf8.encode(body)]);
return new http.StreamedResponse(stream, status, headers: headers);
}
buildUnnamed5018() {
var o = new core.List<core.String>();
o.add("foo");
o.add("foo");
return o;
}
checkUnnamed5018(core.List<core.String> o) {
unittest.expect(o, unittest.hasLength(2));
unittest.expect(o[0], unittest.equals('foo'));
unittest.expect(o[1], unittest.equals('foo'));
}
core.int buildCounterCreateProfileRequest = 0;
buildCreateProfileRequest() {
var o = new api.CreateProfileRequest();
buildCounterCreateProfileRequest++;
if (buildCounterCreateProfileRequest < 3) {
o.deployment = buildDeployment();
o.profileType = buildUnnamed5018();
}
buildCounterCreateProfileRequest--;
return o;
}
checkCreateProfileRequest(api.CreateProfileRequest o) {
buildCounterCreateProfileRequest++;
if (buildCounterCreateProfileRequest < 3) {
checkDeployment(o.deployment);
checkUnnamed5018(o.profileType);
}
buildCounterCreateProfileRequest--;
}
buildUnnamed5019() {
var o = new core.Map<core.String, core.String>();
o["x"] = "foo";
o["y"] = "foo";
return o;
}
checkUnnamed5019(core.Map<core.String, core.String> o) {
unittest.expect(o, unittest.hasLength(2));
unittest.expect(o["x"], unittest.equals('foo'));
unittest.expect(o["y"], unittest.equals('foo'));
}
core.int buildCounterDeployment = 0;
buildDeployment() {
var o = new api.Deployment();
buildCounterDeployment++;
if (buildCounterDeployment < 3) {
o.labels = buildUnnamed5019();
o.projectId = "foo";
o.target = "foo";
}
buildCounterDeployment--;
return o;
}
checkDeployment(api.Deployment o) {
buildCounterDeployment++;
if (buildCounterDeployment < 3) {
checkUnnamed5019(o.labels);
unittest.expect(o.projectId, unittest.equals('foo'));
unittest.expect(o.target, unittest.equals('foo'));
}
buildCounterDeployment--;
}
buildUnnamed5020() {
var o = new core.Map<core.String, core.String>();
o["x"] = "foo";
o["y"] = "foo";
return o;
}
checkUnnamed5020(core.Map<core.String, core.String> o) {
unittest.expect(o, unittest.hasLength(2));
unittest.expect(o["x"], unittest.equals('foo'));
unittest.expect(o["y"], unittest.equals('foo'));
}
core.int buildCounterProfile = 0;
buildProfile() {
var o = new api.Profile();
buildCounterProfile++;
if (buildCounterProfile < 3) {
o.deployment = buildDeployment();
o.duration = "foo";
o.labels = buildUnnamed5020();
o.name = "foo";
o.profileBytes = "foo";
o.profileType = "foo";
}
buildCounterProfile--;
return o;
}
checkProfile(api.Profile o) {
buildCounterProfile++;
if (buildCounterProfile < 3) {
checkDeployment(o.deployment);
unittest.expect(o.duration, unittest.equals('foo'));
checkUnnamed5020(o.labels);
unittest.expect(o.name, unittest.equals('foo'));
unittest.expect(o.profileBytes, unittest.equals('foo'));
unittest.expect(o.profileType, unittest.equals('foo'));
}
buildCounterProfile--;
}
main() {
unittest.group("obj-schema-CreateProfileRequest", () {
unittest.test("to-json--from-json", () {
var o = buildCreateProfileRequest();
var od = new api.CreateProfileRequest.fromJson(o.toJson());
checkCreateProfileRequest(od);
});
});
unittest.group("obj-schema-Deployment", () {
unittest.test("to-json--from-json", () {
var o = buildDeployment();
var od = new api.Deployment.fromJson(o.toJson());
checkDeployment(od);
});
});
unittest.group("obj-schema-Profile", () {
unittest.test("to-json--from-json", () {
var o = buildProfile();
var od = new api.Profile.fromJson(o.toJson());
checkProfile(od);
});
});
unittest.group("resource-ProjectsProfilesResourceApi", () {
unittest.test("method--create", () {
var mock = new HttpServerMock();
api.ProjectsProfilesResourceApi res =
new api.CloudprofilerApi(mock).projects.profiles;
var arg_request = buildCreateProfileRequest();
var arg_parent = "foo";
var arg_$fields = "foo";
mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
var obj = new api.CreateProfileRequest.fromJson(json);
checkCreateProfileRequest(obj);
var path = (req.url).path;
var pathOffset = 0;
var index;
var subPart;
unittest.expect(
path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
pathOffset += 1;
unittest.expect(
path.substring(pathOffset, pathOffset + 3), unittest.equals("v2/"));
pathOffset += 3;
// NOTE: We cannot test reserved expansions due to the inability to reverse the operation;
var query = (req.url).query;
var queryOffset = 0;
var queryMap = <core.String, core.List<core.String>>{};
addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
parseBool(n) {
if (n == "true") return true;
if (n == "false") return false;
if (n == null) return null;
throw new core.ArgumentError("Invalid boolean: $n");
}
if (query.length > 0) {
for (var part in query.split("&")) {
var keyvalue = part.split("=");
addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
core.Uri.decodeQueryComponent(keyvalue[1]));
}
}
unittest.expect(queryMap["fields"].first, unittest.equals(arg_$fields));
var h = {
"content-type": "application/json; charset=utf-8",
};
var resp = convert.json.encode(buildProfile());
return new async.Future.value(stringResponse(200, h, resp));
}), true);
res
.create(arg_request, arg_parent, $fields: arg_$fields)
.then(unittest.expectAsync1(((response) {
checkProfile(response);
})));
});
unittest.test("method--createOffline", () {
var mock = new HttpServerMock();
api.ProjectsProfilesResourceApi res =
new api.CloudprofilerApi(mock).projects.profiles;
var arg_request = buildProfile();
var arg_parent = "foo";
var arg_$fields = "foo";
mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
var obj = new api.Profile.fromJson(json);
checkProfile(obj);
var path = (req.url).path;
var pathOffset = 0;
var index;
var subPart;
unittest.expect(
path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
pathOffset += 1;
unittest.expect(
path.substring(pathOffset, pathOffset + 3), unittest.equals("v2/"));
pathOffset += 3;
// NOTE: We cannot test reserved expansions due to the inability to reverse the operation;
var query = (req.url).query;
var queryOffset = 0;
var queryMap = <core.String, core.List<core.String>>{};
addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
parseBool(n) {
if (n == "true") return true;
if (n == "false") return false;
if (n == null) return null;
throw new core.ArgumentError("Invalid boolean: $n");
}
if (query.length > 0) {
for (var part in query.split("&")) {
var keyvalue = part.split("=");
addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
core.Uri.decodeQueryComponent(keyvalue[1]));
}
}
unittest.expect(queryMap["fields"].first, unittest.equals(arg_$fields));
var h = {
"content-type": "application/json; charset=utf-8",
};
var resp = convert.json.encode(buildProfile());
return new async.Future.value(stringResponse(200, h, resp));
}), true);
res
.createOffline(arg_request, arg_parent, $fields: arg_$fields)
.then(unittest.expectAsync1(((response) {
checkProfile(response);
})));
});
unittest.test("method--patch", () {
var mock = new HttpServerMock();
api.ProjectsProfilesResourceApi res =
new api.CloudprofilerApi(mock).projects.profiles;
var arg_request = buildProfile();
var arg_name = "foo";
var arg_updateMask = "foo";
var arg_$fields = "foo";
mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
var obj = new api.Profile.fromJson(json);
checkProfile(obj);
var path = (req.url).path;
var pathOffset = 0;
var index;
var subPart;
unittest.expect(
path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
pathOffset += 1;
unittest.expect(
path.substring(pathOffset, pathOffset + 3), unittest.equals("v2/"));
pathOffset += 3;
// NOTE: We cannot test reserved expansions due to the inability to reverse the operation;
var query = (req.url).query;
var queryOffset = 0;
var queryMap = <core.String, core.List<core.String>>{};
addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
parseBool(n) {
if (n == "true") return true;
if (n == "false") return false;
if (n == null) return null;
throw new core.ArgumentError("Invalid boolean: $n");
}
if (query.length > 0) {
for (var part in query.split("&")) {
var keyvalue = part.split("=");
addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
core.Uri.decodeQueryComponent(keyvalue[1]));
}
}
unittest.expect(
queryMap["updateMask"].first, unittest.equals(arg_updateMask));
unittest.expect(queryMap["fields"].first, unittest.equals(arg_$fields));
var h = {
"content-type": "application/json; charset=utf-8",
};
var resp = convert.json.encode(buildProfile());
return new async.Future.value(stringResponse(200, h, resp));
}), true);
res
.patch(arg_request, arg_name,
updateMask: arg_updateMask, $fields: arg_$fields)
.then(unittest.expectAsync1(((response) {
checkProfile(response);
})));
});
});
}