chore(shorebird_cli): improve missing file exceptions in ArtifactManager.createDiff (#1922)
This commit is contained in:
@@ -22,6 +22,20 @@ class ArtifactManager {
|
||||
required String releaseArtifactPath,
|
||||
required String patchArtifactPath,
|
||||
}) async {
|
||||
if (!File(releaseArtifactPath).existsSync()) {
|
||||
throw FileSystemException(
|
||||
'Release artifact does not exist',
|
||||
releaseArtifactPath,
|
||||
);
|
||||
}
|
||||
|
||||
if (!File(patchArtifactPath).existsSync()) {
|
||||
throw FileSystemException(
|
||||
'Patch artifact does not exist',
|
||||
patchArtifactPath,
|
||||
);
|
||||
}
|
||||
|
||||
final tempDir = await Directory.systemTemp.createTemp();
|
||||
final diffPath = p.join(tempDir.path, 'diff.patch');
|
||||
final diffExecutable = p.join(
|
||||
|
||||
@@ -69,8 +69,64 @@ void main() {
|
||||
});
|
||||
|
||||
group('createDiff', () {
|
||||
const releaseArtifactPath = 'path/to/release_artifact';
|
||||
const patchArtifactPath = 'path/to/patch_artifact';
|
||||
late File releaseArtifactFile;
|
||||
late File patchArtifactFile;
|
||||
|
||||
setUp(() {
|
||||
final tmpDir = Directory.systemTemp.createTempSync();
|
||||
releaseArtifactFile = File(p.join(tmpDir.path, 'release_artifact'))
|
||||
..createSync(recursive: true);
|
||||
patchArtifactFile = File(p.join(tmpDir.path, 'patch_artifact'))
|
||||
..createSync(recursive: true);
|
||||
});
|
||||
|
||||
test('throws error when release artifact file does not exist', () async {
|
||||
await expectLater(
|
||||
() => runWithOverrides(
|
||||
() async => artifactManager.createDiff(
|
||||
releaseArtifactPath: 'not/a/real/file',
|
||||
patchArtifactPath: patchArtifactFile.path,
|
||||
),
|
||||
),
|
||||
throwsA(
|
||||
isA<FileSystemException>()
|
||||
.having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
'Release artifact does not exist',
|
||||
)
|
||||
.having(
|
||||
(e) => e.path,
|
||||
'path',
|
||||
'not/a/real/file',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws error when patch artfiact file does not exist', () async {
|
||||
await expectLater(
|
||||
() => runWithOverrides(
|
||||
() async => artifactManager.createDiff(
|
||||
releaseArtifactPath: releaseArtifactFile.path,
|
||||
patchArtifactPath: 'not/a/real/file',
|
||||
),
|
||||
),
|
||||
throwsA(
|
||||
isA<FileSystemException>()
|
||||
.having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
'Patch artifact does not exist',
|
||||
)
|
||||
.having(
|
||||
(e) => e.path,
|
||||
'path',
|
||||
'not/a/real/file',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws error when creating diff fails', () async {
|
||||
const stdout = 'uh oh';
|
||||
@@ -82,8 +138,8 @@ void main() {
|
||||
await expectLater(
|
||||
() => runWithOverrides(
|
||||
() async => artifactManager.createDiff(
|
||||
releaseArtifactPath: releaseArtifactPath,
|
||||
patchArtifactPath: patchArtifactPath,
|
||||
releaseArtifactPath: releaseArtifactFile.path,
|
||||
patchArtifactPath: patchArtifactFile.path,
|
||||
),
|
||||
),
|
||||
throwsA(
|
||||
@@ -101,8 +157,8 @@ void main() {
|
||||
test('returns diff path when creating diff succeeds', () async {
|
||||
final diffPath = await runWithOverrides(
|
||||
() => artifactManager.createDiff(
|
||||
releaseArtifactPath: releaseArtifactPath,
|
||||
patchArtifactPath: patchArtifactPath,
|
||||
releaseArtifactPath: releaseArtifactFile.path,
|
||||
patchArtifactPath: patchArtifactFile.path,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -112,8 +168,8 @@ void main() {
|
||||
p.join(cacheArtifactDirectory.path, 'patch'),
|
||||
any(
|
||||
that: containsAllInOrder([
|
||||
releaseArtifactPath,
|
||||
patchArtifactPath,
|
||||
releaseArtifactFile.path,
|
||||
patchArtifactFile.path,
|
||||
endsWith('diff.patch'),
|
||||
]),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user