fix(storage): handle non-existing entry for filesByPrefix

This commit is contained in:
brian.mulier
2023-12-05 15:35:12 +01:00
committed by brian-mulier-p
parent e27a99bc9a
commit 2ff0862ad3
2 changed files with 8 additions and 2 deletions

View File

@@ -115,7 +115,7 @@ public abstract class StorageTestSuite {
@Test
void search() throws IOException {
storageInterface.put(null, URI.create("/namespace/file.txt"), new ByteArrayInputStream(new byte[0]));
storageInterface.put("tenant", URI.create("/namespace/file.txt"), new ByteArrayInputStream(new byte[0]));
storageInterface.put("tenant", URI.create("/namespace/tenant_file.txt"), new ByteArrayInputStream(new byte[0]));
storageInterface.put(null, URI.create("/namespace/another_file.json"), new ByteArrayInputStream(new byte[0]));
storageInterface.put(null, URI.create("/namespace/folder/file.txt"), new ByteArrayInputStream(new byte[0]));
storageInterface.put(null, URI.create("/namespace/folder/some.yaml"), new ByteArrayInputStream(new byte[0]));
@@ -131,7 +131,7 @@ public abstract class StorageTestSuite {
));
res = storageInterface.filesByPrefix("tenant", URI.create("/namespace"));
assertThat(res, containsInAnyOrder(URI.create("kestra:///namespace/file.txt")));
assertThat(res, containsInAnyOrder(URI.create("kestra:///namespace/tenant_file.txt")));
res = storageInterface.filesByPrefix(null, URI.create("/namespace/folder"));
assertThat(res, containsInAnyOrder(
@@ -142,6 +142,9 @@ public abstract class StorageTestSuite {
res = storageInterface.filesByPrefix(null, URI.create("/namespace/folder/sub"));
assertThat(res, containsInAnyOrder(URI.create("kestra:///namespace/folder/sub/script.py")));
res = storageInterface.filesByPrefix(null, URI.create("/namespace/non-existing"));
assertThat(res, empty());
}
//region test LIST

View File

@@ -11,6 +11,7 @@ import java.net.URI;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
@@ -61,6 +62,8 @@ public class LocalStorage implements StorageInterface {
return URI.create("kestra://" + prefixPath + (prefixPath.endsWith("/") ? "" : "/") + path);
})
.toList();
} catch (NoSuchFileException e) {
return Collections.emptyList();
}
}