Fix relocated desktop tool paths and package release 0.2.2
This commit is contained in:
1 parent
efaf16de18
commit
e366eb5bec
14 files changed
+250
-33
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:ads_manager/data/tool_paths.dart';
|
||||
import 'package:ads_manager/data/manager_repository.dart';
|
||||
|
||||
void main() {
|
||||
group('relocated tool paths', () {
|
||||
late Directory temp;
|
||||
late String bundle;
|
||||
late ToolPaths paths;
|
||||
String exe(String name) => Platform.isWindows ? '$name.exe' : name;
|
||||
String create(String path) {
|
||||
final file = File(path);
|
||||
file.parent.createSync(recursive: true);
|
||||
file.writeAsStringSync('fixture');
|
||||
return file.path;
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
temp = Directory.systemTemp.createTempSync('ads-relocate');
|
||||
bundle = p.join(temp.path, 'Programs', 'TongTongStudio', 'ADS-Flutter');
|
||||
paths = ToolPaths(base: bundle, searchPath: '');
|
||||
});
|
||||
tearDown(() => temp.deleteSync(recursive: true));
|
||||
for (final oldExists in [false, true]) {
|
||||
test('migrates old install, old file exists=$oldExists', () {
|
||||
final old = p.join(
|
||||
temp.path,
|
||||
'Programs',
|
||||
'TTSTD',
|
||||
'ADS-Flutter',
|
||||
exe('ads-client'),
|
||||
);
|
||||
if (oldExists) create(old);
|
||||
final current = create(p.join(bundle, exe('ads-client')));
|
||||
expect(
|
||||
paths.resolve('ads-client', configured: old, required: true),
|
||||
current,
|
||||
);
|
||||
});
|
||||
}
|
||||
test('preserves a valid custom executable', () {
|
||||
create(p.join(bundle, exe('adb')));
|
||||
final custom = create(p.join(temp.path, 'SDK', exe('adb')));
|
||||
expect(paths.resolve('adb', configured: custom), custom);
|
||||
});
|
||||
test('migration persists tools and preserves other settings', () async {
|
||||
final repository = ManagerRepository((_) {}, paths: paths)
|
||||
..storage = temp;
|
||||
repository.settings.credential = 'private-client.env';
|
||||
repository.settings.usbMode = true;
|
||||
repository.settings.client = p.join(
|
||||
temp.path,
|
||||
'Programs',
|
||||
'TTSTD',
|
||||
'ADS-Flutter',
|
||||
exe('ads-client'),
|
||||
);
|
||||
create(p.join(bundle, exe('ads-client')));
|
||||
create(p.join(bundle, 'tools', 'scrcpy', exe('adb')));
|
||||
create(p.join(bundle, 'tools', 'scrcpy', exe('scrcpy')));
|
||||
await repository.repairToolPaths();
|
||||
final saved = jsonDecode(
|
||||
File(p.join(temp.path, 'settings.json')).readAsStringSync(),
|
||||
);
|
||||
expect(saved['client'], p.join(bundle, exe('ads-client')));
|
||||
expect(saved['adb'], p.join(bundle, 'tools', 'scrcpy', exe('adb')));
|
||||
expect(saved['credential'], 'private-client.env');
|
||||
expect(saved['usbMode'], true);
|
||||
});
|
||||
test(
|
||||
'missing tool fails before allocating ports or creating sessions',
|
||||
() async {
|
||||
final repository = ManagerRepository((_) {}, paths: paths)
|
||||
..storage = temp
|
||||
..token = 'a' * 32;
|
||||
await expectLater(
|
||||
repository.connect('phone'),
|
||||
throwsA(
|
||||
isA<FileSystemException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
contains('重新安装'),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(repository.reservedPorts, isEmpty);
|
||||
expect(repository.sessions, isEmpty);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user