mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-07 00:50:27 +00:00
feat: move native communication to FFI (#1457)
This commit is contained in:
86 files changed
+4558
-886
No files matched your search
@@ -17,4 +17,36 @@ void main() {
|
||||
|
||||
expect(DownloaderConfig.fromJson(json).autoStartTasks, isFalse);
|
||||
});
|
||||
|
||||
test('REST server settings round-trip through the Go downloader config', () {
|
||||
final config = DownloaderConfig()
|
||||
..api = ApiServerConfig(enable: true, network: 'tcp', address: '127.0.0.1:4321', token: 'secret');
|
||||
|
||||
final decoded = DownloaderConfig.fromJson(config.toJson()).api;
|
||||
expect(decoded.enable, isTrue);
|
||||
expect(decoded.network, 'tcp');
|
||||
expect(decoded.address, '127.0.0.1:4321');
|
||||
expect(decoded.token, 'secret');
|
||||
});
|
||||
|
||||
test('Flutter preferences round-trip through the Go-owned extra config', () {
|
||||
final config = DownloaderConfig();
|
||||
config.extra
|
||||
..windowState = WindowStateConfig(isMaximized: true, width: 1280, height: 720)
|
||||
..bookmarks = {'downloads': 'D:/Downloads'}
|
||||
..createHistory = ['https://example.com/file.zip']
|
||||
..runAsMenubarApp = true
|
||||
..analyticsEnabled = false
|
||||
..analyticsClientId = 'client-id';
|
||||
|
||||
final decoded = DownloaderConfig.fromJson(config.toJson()).extra;
|
||||
expect(decoded.windowState.isMaximized, isTrue);
|
||||
expect(decoded.windowState.width, 1280);
|
||||
expect(decoded.windowState.height, 720);
|
||||
expect(decoded.bookmarks, {'downloads': 'D:/Downloads'});
|
||||
expect(decoded.createHistory, ['https://example.com/file.zip']);
|
||||
expect(decoded.runAsMenubarApp, isTrue);
|
||||
expect(decoded.analyticsEnabled, isFalse);
|
||||
expect(decoded.analyticsClientId, 'client-id');
|
||||
});
|
||||
}
|
||||
@@ -1,46 +1,26 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart' as dio;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/api/api.dart' as api;
|
||||
import 'package:gopeed/api/model/options.dart';
|
||||
import 'package:gopeed/api/model/request.dart';
|
||||
import 'package:gopeed/api/model/resolve_task.dart';
|
||||
import 'package:gopeed/core/network/gopeed/gopeed_transport.dart';
|
||||
|
||||
void main() {
|
||||
test('resolve sends the complete resolve task for magnet links', () async {
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||
addTearDown(server.close);
|
||||
|
||||
late Map<String, dynamic> requestBody;
|
||||
final responseHandled = Completer<void>();
|
||||
server.listen((request) async {
|
||||
requestBody = jsonDecode(await utf8.decoder.bind(request).join()) as Map<String, dynamic>;
|
||||
request.response.headers.contentType = ContentType.json;
|
||||
request.response.write(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'id': 'resolved-id',
|
||||
'res': {'name': 'sample', 'size': 0, 'range': false, 'files': <Object>[], 'hash': ''},
|
||||
},
|
||||
}),
|
||||
);
|
||||
await request.response.close();
|
||||
responseHandled.complete();
|
||||
});
|
||||
|
||||
api.init('tcp', '127.0.0.1:${server.port}', '');
|
||||
final transport = _RecordingTransport();
|
||||
api.setTransportForTesting(transport);
|
||||
final result = await api.resolve(
|
||||
ResolveTask(
|
||||
req: Request(url: 'magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567'),
|
||||
opts: Options(path: '/downloads', selectFiles: const []),
|
||||
),
|
||||
);
|
||||
await responseHandled.future;
|
||||
|
||||
expect(result.id, 'resolved-id');
|
||||
final requestBody = transport.data as Map<String, dynamic>;
|
||||
expect(requestBody.keys, containsAll(<String>['req', 'opts']));
|
||||
expect(
|
||||
(requestBody['req'] as Map<String, dynamic>)['url'],
|
||||
@@ -49,3 +29,32 @@ void main() {
|
||||
expect((requestBody['opts'] as Map<String, dynamic>)['path'], '/downloads');
|
||||
});
|
||||
}
|
||||
|
||||
class _RecordingTransport implements GopeedTransport {
|
||||
dynamic data;
|
||||
|
||||
@override
|
||||
Future<dynamic> request(
|
||||
String path, {
|
||||
String method = 'GET',
|
||||
dynamic data,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
}) async {
|
||||
this.data = jsonDecode(jsonEncode(data));
|
||||
return {
|
||||
'code': 0,
|
||||
'data': {
|
||||
'id': 'resolved-id',
|
||||
'res': {'name': 'sample', 'size': 0, 'range': false, 'files': <Object>[], 'hash': ''},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String join(String path) => path;
|
||||
|
||||
@override
|
||||
Future<dio.Response<String>> proxyRequest(String uri, {dynamic data, dio.Options? options}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user