[flutter_tools] add unit test for error 32 in cache deletion (#76714)

This commit is contained in:
Jonah Williams 2021-02-24 12:11:03 -08:00 committed by GitHub
parent 109e0bb9f5
commit 114ba8cc3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -438,6 +438,38 @@ void main() {
expect(fileSystem.file('a/b/c/d'), isNot(exists));
expect(logger.errorText, isEmpty);
});
testWithoutContext('ArtifactUpdater will tool exit if deleting the existing artifacts fails with 32 on windows', () async {
const int kSharingViolation = 32;
final FileExceptionHandler handler = FileExceptionHandler();
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
fileSystem: fileSystem,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
platform: FakePlatform(operatingSystem: 'windows'),
httpClient: FakeHttpClient.any(),
tempStorage: fileSystem.currentDirectory.childDirectory('temp')
..createSync(),
);
final Directory errorDirectory = fileSystem.currentDirectory
.childDirectory('out')
.childDirectory('test')
..createSync(recursive: true);
handler.addError(errorDirectory, FileSystemOp.delete, const FileSystemException('', '', OSError('', kSharingViolation)));
await expectLater(() async => await artifactUpdater.downloadZippedTarball(
'test message',
Uri.parse('http://test.zip'),
fileSystem.currentDirectory.childDirectory('out'),
), throwsToolExit(
message: 'Failed to delete /out/test because the local file/directory is in use by another process'
));
expect(fileSystem.file('out/test'), isNot(exists));
});
}
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {