mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-19 18:05:41 -05:00
feat(core): standardize input type file
remove exception for `inputs.file.uri` to `inputs.file` to be consistent relate to #78
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
package org.kestra.storage.local;
|
||||
|
||||
import org.kestra.core.storages.StorageInterface;
|
||||
import org.kestra.core.storages.StorageObject;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@LocalStorageEnabled
|
||||
@@ -50,7 +49,7 @@ public class LocalStorage implements StorageInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageObject put(URI uri, InputStream data) throws IOException {
|
||||
public URI put(URI uri, InputStream data) throws IOException {
|
||||
this.createDirectory(uri);
|
||||
|
||||
OutputStream outStream = new FileOutputStream(getPath(uri).toFile());
|
||||
@@ -64,8 +63,6 @@ public class LocalStorage implements StorageInterface {
|
||||
outStream.close();
|
||||
data.close();
|
||||
|
||||
URI result = URI.create("kestra://" + uri.getPath());
|
||||
|
||||
return new StorageObject(this, result);
|
||||
return URI.create("kestra://" + uri.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import com.google.common.io.CharStreams;
|
||||
import io.micronaut.test.annotation.MicronautTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kestra.core.storages.StorageInterface;
|
||||
import org.kestra.core.storages.StorageObject;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
@@ -14,6 +12,7 @@ import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -24,7 +23,7 @@ class LocalStorageTest {
|
||||
@Inject
|
||||
StorageInterface storageInterface;
|
||||
|
||||
private StorageObject putFile(URL resource, String path) throws Exception {
|
||||
private URI putFile(URL resource, String path) throws Exception {
|
||||
return storageInterface.put(
|
||||
new URI(path),
|
||||
new FileInputStream(Objects.requireNonNull(resource).getFile())
|
||||
@@ -55,13 +54,13 @@ class LocalStorageTest {
|
||||
@Test
|
||||
void put() throws Exception {
|
||||
URL resource = LocalStorageTest.class.getClassLoader().getResource("application.yml");
|
||||
StorageObject put = this.putFile(resource, "/file/storage/put.yml");
|
||||
URI put = this.putFile(resource, "/file/storage/put.yml");
|
||||
InputStream get = storageInterface.get(new URI("/file/storage/put.yml"));
|
||||
|
||||
assertThat(put.getUri().toString(), is(new URI("kestra:///file/storage/put.yml").toString()));
|
||||
assertThat(put.toString(), is(new URI("kestra:///file/storage/put.yml").toString()));
|
||||
assertThat(
|
||||
CharStreams.toString(new InputStreamReader(get)),
|
||||
is(CharStreams.toString(new InputStreamReader(new FileInputStream(Objects.requireNonNull(resource).getFile()))))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user