| // Copyright 2024, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| import 'dart:io' as io; |
| |
| import 'package:deps/build.dart'; |
| import 'package:deps/package.dart'; |
| import 'package:file/file.dart'; |
| import 'package:file/local.dart'; |
| import 'package:file/memory.dart'; |
| import 'package:test/test.dart'; |
| |
| import 'command_test.dart'; |
| |
| class TestUnzipPackage extends Package with UnzipBuild { |
| TestUnzipPackage(String name) : super(name, Uri.parse('https://example.com')); |
| |
| @override |
| Future<List<FileSystemEntity>> fetch(Directory workingDir) { |
| throw UnimplementedError(); |
| } |
| |
| @override |
| Future<bool> check(Directory artifacts) { |
| throw UnimplementedError(); |
| } |
| |
| @override |
| Future<void> upload(Directory artifacts, bool provenance) { |
| throw UnimplementedError(); |
| } |
| } |
| |
| void main() { |
| test('unzip throws when input is a directory', () async { |
| final fileSystem = MemoryFileSystem.test(); |
| final temp = await fileSystem.directory('/temp').create(); |
| final dir = await temp.childDirectory('d').create(); |
| |
| final package = TestUnzipPackage('dart/path/package/platform'); |
| expect(package.build([dir], temp), throwsStateError); |
| }); |
| |
| group('unzip', () { |
| final fileSystem = LocalFileSystem(); |
| late Directory workingDir; |
| |
| setUp(() async => |
| workingDir = await fileSystem.systemTempDirectory.createTemp()); |
| tearDown(() async => await workingDir.delete(recursive: true)); |
| |
| for (var ending in ['zip', 'tar.gz', 'tar.bz2']) { |
| test('unzip $ending', () async { |
| final archive = fileSystem.file('test/data/test.$ending'); |
| final package = TestUnzipPackage('dart/path/package/platform'); |
| final dir = await package.build([archive], workingDir); |
| expect(dir.parent.path, workingDir.path); |
| expect( |
| dir |
| .listSync(recursive: true) |
| .map((f) => f.path.substring(workingDir.path.length)), |
| unorderedEquals([ |
| '/unzipped/a', |
| '/unzipped/d', |
| '/unzipped/d/b', |
| ])); |
| }); |
| } |
| }); |
| |
| test('unzip unsupported format', () async { |
| final fileSystem = MemoryFileSystem.test(); |
| final temp = await fileSystem.directory('/temp').create(); |
| final archive = await temp.childFile('a.zipperoo').create(); |
| final package = TestUnzipPackage('dart/path/package/platform'); |
| |
| expect(package.build([archive], temp), throwsStateError); |
| }); |
| |
| test('unzip failed', () async { |
| final fileSystem = MemoryFileSystem.test(); |
| final temp = await fileSystem.directory('/temp').create(); |
| final archive = await temp.childFile('a.zip').create(); |
| final package = TestUnzipPackage('dart/path/package/platform'); |
| mockedRun(io.ProcessResult(123, 1, null, null), 'unzip', null, |
| () => expect(package.build([archive], temp), throwsFormatException)); |
| }); |
| } |