macOS unzip then rsync to delete stale artifacts (#85075)

This commit is contained in:
Jenn Magder
2021-06-22 17:10:56 -07:00
committed by GitHub
parent 9e082f6ce9
commit 40428fa0ea
2 changed files with 113 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
@@ -536,6 +537,79 @@ void main() {
);
});
group('unzip on macOS', () {
testWithoutContext('falls back to unzip when rsync cannot run', () {
final FileSystem fileSystem = MemoryFileSystem.test();
fakeProcessManager.excludedExecutables.add('rsync');
final BufferLogger logger = BufferLogger.test();
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: logger,
platform: FakePlatform(operatingSystem: 'macos'),
processManager: fakeProcessManager,
);
final Directory targetDirectory = fileSystem.currentDirectory;
fakeProcessManager.addCommand(FakeCommand(
command: <String>['unzip', '-o', '-q', 'foo.zip', '-d', targetDirectory.path],
));
macOSUtils.unzip(fileSystem.file('foo.zip'), targetDirectory);
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(logger.traceText, contains('Unable to find rsync'));
});
testWithoutContext('unzip and rsyncs', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'macos'),
processManager: fakeProcessManager,
);
final Directory targetDirectory = fileSystem.currentDirectory;
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
fakeProcessManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'unzip',
'-o',
'-q',
'foo.zip',
'-d',
tempDirectory.path,
],
onRun: () {
expect(tempDirectory, exists);
tempDirectory.childDirectory('dirA').childFile('fileA').createSync(recursive: true);
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
},
),
FakeCommand(command: <String>[
'rsync',
'-av',
'--delete',
tempDirectory.childDirectory('dirA').path,
targetDirectory.path,
]),
FakeCommand(command: <String>[
'rsync',
'-av',
'--delete',
tempDirectory.childDirectory('dirB').path,
targetDirectory.path,
]),
]);
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(tempDirectory, isNot(exists));
});
});
group('display an install message when unzip cannot be run', () {
testWithoutContext('Linux', () {
final FileSystem fileSystem = MemoryFileSystem.test();