feat(tasks): add a storage.delete tasks to allow deletion of internal storage file

This commit is contained in:
tchiotludo
2020-07-03 11:43:27 +02:00
parent f80cfea3d4
commit 55c2cfe2da
5 changed files with 151 additions and 0 deletions

View File

@@ -66,4 +66,14 @@ public class LocalStorage implements StorageInterface {
return URI.create("kestra://" + uri.getPath());
}
@Override
public boolean delete(URI uri) throws IOException {
File file = getPath(URI.create(uri.getPath())).toFile();
if (!file.exists()) {
return false;
}
return file.delete();
}
}

View File

@@ -62,5 +62,15 @@ class LocalStorageTest {
CharStreams.toString(new InputStreamReader(get)),
is(CharStreams.toString(new InputStreamReader(new FileInputStream(Objects.requireNonNull(resource).getFile()))))
);
boolean delete = storageInterface.delete(new URI("/file/storage/put.yml"));
assertThat(delete, is(true));
delete = storageInterface.delete(new URI("/file/storage/put.yml"));
assertThat(delete, is(false));
assertThrows(FileNotFoundException.class, () -> {
storageInterface.get(new URI("/file/storage/put.yml"));
});
}
}