diff --git a/packages/shorebird_cli/lib/src/artifact_manager.dart b/packages/shorebird_cli/lib/src/artifact_manager.dart index 7bdab5ca..55a0271a 100644 --- a/packages/shorebird_cli/lib/src/artifact_manager.dart +++ b/packages/shorebird_cli/lib/src/artifact_manager.dart @@ -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( diff --git a/packages/shorebird_cli/test/src/artifact_manager_test.dart b/packages/shorebird_cli/test/src/artifact_manager_test.dart index 26a5935f..2d1825aa 100644 --- a/packages/shorebird_cli/test/src/artifact_manager_test.dart +++ b/packages/shorebird_cli/test/src/artifact_manager_test.dart @@ -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() + .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() + .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'), ]), ),