blob: b52168b291daa806c8070f2f47e6eba4a53a4bec [file] [log] [blame]
// ignore_for_file: camel_case_types
// ignore_for_file: comment_references
// ignore_for_file: constant_identifier_names
// ignore_for_file: directives_ordering
// ignore_for_file: library_names
// ignore_for_file: lines_longer_than_80_chars
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: omit_local_variable_types
// ignore_for_file: prefer_final_locals
// ignore_for_file: prefer_interpolation_to_compose_strings
// ignore_for_file: unnecessary_brace_in_string_interps
// ignore_for_file: unnecessary_cast
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: unnecessary_string_interpolations
// ignore_for_file: avoid_returning_null
// ignore_for_file: cascade_invocations
// ignore_for_file: prefer_single_quotes
// ignore_for_file: unnecessary_lambdas
// ignore_for_file: unused_local_variable
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;
}
@core.override
async.Future<http.StreamedResponse> send(http.BaseRequest request) async {
if (_expectJson) {
final jsonString =
await request.finalize().transform(convert.utf8.decoder).join('');
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 {
final data = await stream.toBytes();
return _callback(request, data);
}
}
}
}
http.StreamedResponse stringResponse(core.int status,
core.Map<core.String, core.String> headers, core.String body) {
var stream = async.Stream.fromIterable([convert.utf8.encode(body)]);
return http.StreamedResponse(stream, status, headers: headers);
}
core.List<core.String> buildUnnamed2262() {
var o = <core.String>[];
o.add('foo');
o.add('foo');
return o;
}
void checkUnnamed2262(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;
api.CreateProfileRequest buildCreateProfileRequest() {
var o = api.CreateProfileRequest();
buildCounterCreateProfileRequest++;
if (buildCounterCreateProfileRequest < 3) {
o.deployment = buildDeployment();
o.profileType = buildUnnamed2262();
}
buildCounterCreateProfileRequest--;
return o;
}
void checkCreateProfileRequest(api.CreateProfileRequest o) {
buildCounterCreateProfileRequest++;
if (buildCounterCreateProfileRequest < 3) {
checkDeployment(o.deployment);
checkUnnamed2262(o.profileType);
}
buildCounterCreateProfileRequest--;
}
core.Map<core.String, core.String> buildUnnamed2263() {
var o = <core.String, core.String>{};
o['x'] = 'foo';
o['y'] = 'foo';
return o;
}
void checkUnnamed2263(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;
api.Deployment buildDeployment() {
var o = api.Deployment();
buildCounterDeployment++;
if (buildCounterDeployment < 3) {
o.labels = buildUnnamed2263();
o.projectId = 'foo';
o.target = 'foo';
}
buildCounterDeployment--;
return o;
}
void checkDeployment(api.Deployment o) {
buildCounterDeployment++;
if (buildCounterDeployment < 3) {
checkUnnamed2263(o.labels);
unittest.expect(o.projectId, unittest.equals('foo'));
unittest.expect(o.target, unittest.equals('foo'));
}
buildCounterDeployment--;
}
core.Map<core.String, core.String> buildUnnamed2264() {
var o = <core.String, core.String>{};
o['x'] = 'foo';
o['y'] = 'foo';
return o;
}
void checkUnnamed2264(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;
api.Profile buildProfile() {
var o = api.Profile();
buildCounterProfile++;
if (buildCounterProfile < 3) {
o.deployment = buildDeployment();
o.duration = 'foo';
o.labels = buildUnnamed2264();
o.name = 'foo';
o.profileBytes = 'foo';
o.profileType = 'foo';
}
buildCounterProfile--;
return o;
}
void checkProfile(api.Profile o) {
buildCounterProfile++;
if (buildCounterProfile < 3) {
checkDeployment(o.deployment);
unittest.expect(o.duration, unittest.equals('foo'));
checkUnnamed2264(o.labels);
unittest.expect(o.name, unittest.equals('foo'));
unittest.expect(o.profileBytes, unittest.equals('foo'));
unittest.expect(o.profileType, unittest.equals('foo'));
}
buildCounterProfile--;
}
void main() {
unittest.group('obj-schema-CreateProfileRequest', () {
unittest.test('to-json--from-json', () {
var o = buildCreateProfileRequest();
var od = api.CreateProfileRequest.fromJson(o.toJson());
checkCreateProfileRequest(od);
});
});
unittest.group('obj-schema-Deployment', () {
unittest.test('to-json--from-json', () {
var o = buildDeployment();
var od = api.Deployment.fromJson(o.toJson());
checkDeployment(od);
});
});
unittest.group('obj-schema-Profile', () {
unittest.test('to-json--from-json', () {
var o = buildProfile();
var od = api.Profile.fromJson(o.toJson());
checkProfile(od);
});
});
unittest.group('resource-ProjectsProfilesResourceApi', () {
unittest.test('method--create', () {
var mock = HttpServerMock();
api.ProjectsProfilesResourceApi res =
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 = api.CreateProfileRequest.fromJson(json);
checkCreateProfileRequest(obj);
var path = (req.url).path;
var pathOffset = 0;
core.int index;
core.String 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>>{};
void addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
if (query.isNotEmpty) {
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 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 = HttpServerMock();
api.ProjectsProfilesResourceApi res =
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 = api.Profile.fromJson(json);
checkProfile(obj);
var path = (req.url).path;
var pathOffset = 0;
core.int index;
core.String 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>>{};
void addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
if (query.isNotEmpty) {
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 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 = HttpServerMock();
api.ProjectsProfilesResourceApi res =
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 = api.Profile.fromJson(json);
checkProfile(obj);
var path = (req.url).path;
var pathOffset = 0;
core.int index;
core.String 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>>{};
void addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
if (query.isNotEmpty) {
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 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);
})));
});
});
}