import 'dart:io'; import 'package:cutdex/workspace/persistence/project_location_directory.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { const service = ProjectLocationDirectory(); late Directory root; setUp(() async { root = await Directory.systemTemp.createTemp('cutdex-location-'); }); tearDown(() => root.delete(recursive: true)); test( 'inspection preserves a missing folder, preparation creates it', () async { final folder = Directory('${root.path}/deleted/projects'); expect(await service.inspect(folder.path), ProjectLocationStatus.missing); expect(await folder.exists(), isFalse); expect(await root.list().toList(), isEmpty); await service.prepare(folder.path); expect(await service.inspect(folder.path), ProjectLocationStatus.ready); expect(await folder.list().toList(), isEmpty); }, ); test('a file or broken symlink in the path is never replaced', () async { final file = File('${root.path}/file'); await file.writeAsString('keep'); expect( await service.inspect('${file.path}/projects'), ProjectLocationStatus.unavailable, ); await expectLater( service.prepare('${file.path}/projects'), throwsStateError, ); expect(await file.readAsString(), 'keep'); if (!Platform.isWindows) { final link = Link('${root.path}/link'); await link.create('${root.path}/missing'); expect( await service.inspect('${link.path}/projects'), ProjectLocationStatus.unavailable, ); } }); test('missing external mount paths are not recreated', () async { if (Platform.isWindows) return; final path = '/Volumes/cutdex-offline-${DateTime.now().microsecondsSinceEpoch}/Projects'; expect(await service.inspect(path), ProjectLocationStatus.unavailable); await expectLater(service.prepare(path), throwsStateError); expect(await Directory(path).exists(), isFalse); }); }