Skip to content

Commit

Permalink
fix: test using random didn't work anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Jan 30, 2024
1 parent af1ac7c commit b1cd5d7
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 33 deletions.
17 changes: 11 additions & 6 deletions src/test/java/io/kestra/plugin/fs/AbstractFileTriggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public abstract class AbstractFileTriggerTest {
@Inject
protected RunContextFactory runContextFactory;

@Value("${kestra.variables.globals.random}")
protected String random;

abstract protected String triggeringFlowId();

abstract protected AbstractUtils utils();
Expand Down Expand Up @@ -89,7 +86,7 @@ void moveAction() throws Exception {


String out1 = FriendlyId.createFriendlyId();
String toUploadDir = "/upload/" + random;
String toUploadDir = "/upload/trigger";
utils().upload(toUploadDir + "/" + out1);
String out2 = FriendlyId.createFriendlyId();
utils().upload(toUploadDir + "/" + out2);
Expand All @@ -107,6 +104,9 @@ void moveAction() throws Exception {

assertThat(utils().list(toUploadDir).getFiles().isEmpty(), is(true));
assertThat(utils().list(toUploadDir + "-move").getFiles().size(), is(2));

utils().delete(toUploadDir + "/" + out1);
utils().delete(toUploadDir + "/" + out2);
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ void noneAction() throws Exception {


String out1 = FriendlyId.createFriendlyId();
String toUploadDir = "/upload/" + random + "-none";
String toUploadDir = "/upload/trigger-none";
utils().upload(toUploadDir + "/" + out1);
String out2 = FriendlyId.createFriendlyId();
utils().upload(toUploadDir + "/" + out2);
Expand All @@ -154,6 +154,9 @@ void noneAction() throws Exception {
assertThat(trigger.size(), is(2));

assertThat(utils().list(toUploadDir).getFiles().size(), is(2));

utils().delete(toUploadDir + "/" + out1);
utils().delete(toUploadDir + "/" + out2);
}
}

Expand Down Expand Up @@ -190,14 +193,16 @@ void missing() throws Exception {
Thread.sleep(1000);

String out1 = FriendlyId.createFriendlyId();
utils().upload("/upload/" + random + "/" + out1);
utils().upload("/upload/trigger/" + out1);

queueCount.await(10, TimeUnit.SECONDS);

@SuppressWarnings("unchecked")
java.util.List<URI> trigger = (java.util.List<URI>) last.get().getTrigger().getVariables().get("files");

assertThat(trigger.size(), is(1));

utils().delete("/upload/trigger/" + out1);
}
}
}
3 changes: 3 additions & 0 deletions src/test/java/io/kestra/plugin/fs/AbstractUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.devskiller.friendly_id.FriendlyId;
import io.kestra.core.storages.StorageInterface;
import io.kestra.plugin.fs.sftp.Upload;
import io.kestra.plugin.fs.vfs.Delete;
import io.kestra.plugin.fs.vfs.List;
import jakarta.inject.Inject;

Expand Down Expand Up @@ -35,4 +36,6 @@ public Upload.Output upload(String to) throws Exception {
abstract public Upload.Output upload(URI source, String to) throws Exception;

abstract public List.Output list(String dir) throws Exception;

abstract public Delete.Output delete(String file) throws Exception;
}
4 changes: 2 additions & 2 deletions src/test/java/io/kestra/plugin/fs/ftp/DownloadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.devskiller.friendly_id.FriendlyId;
import com.google.common.collect.ImmutableMap;
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.utils.IdUtils;
import io.kestra.core.utils.TestsUtils;
import io.micronaut.context.annotation.Value;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
Expand All @@ -21,8 +22,7 @@ class DownloadsTest {
@Inject
private FtpUtils ftpUtils;

@Value("${kestra.variables.globals.random}")
private String random;
private final String random = IdUtils.create();

@Test
void run_DeleteAfterDownloads() throws Exception {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/io/kestra/plugin/fs/ftp/FtpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,19 @@ public List.Output list(String dir) throws Exception {
.build()
.run(this.runContextFactory.of());
}

@Override
public Delete.Output delete(String file) throws Exception {
var task = io.kestra.plugin.fs.ftp.Delete.builder()
.id(FtpUtils.class.getSimpleName())
.type(FtpUtils.class.getName())
.uri(file)
.host("localhost")
.port("6621")
.username("guest")
.password("guest")
.build();

return task.run(TestsUtils.mockRunContext(runContextFactory, task, ImmutableMap.of()));
}
}
4 changes: 2 additions & 2 deletions src/test/java/io/kestra/plugin/fs/ftp/UploadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMap;
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.utils.IdUtils;
import io.kestra.core.utils.TestsUtils;
import io.kestra.plugin.fs.vfs.models.File;
import io.micronaut.context.annotation.Value;
Expand All @@ -24,8 +25,7 @@ class UploadsTest {
@Inject
private FtpUtils ftpUtils;

@Value("${kestra.variables.globals.random}")
private String random;
private final String random = IdUtils.create();

@Test
void run() throws Exception {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/io/kestra/plugin/fs/sftp/SftpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.utils.TestsUtils;
import io.kestra.plugin.fs.AbstractUtils;
import io.kestra.plugin.fs.vfs.Delete;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

Expand Down Expand Up @@ -43,4 +44,20 @@ public io.kestra.plugin.fs.vfs.List.Output list(String dir) throws Exception {
.build()
.run(this.runContextFactory.of());
}

@Override
public Delete.Output delete(String file) throws Exception {
var task = io.kestra.plugin.fs.sftp.Delete.builder()
.id(SftpUtils.class.getSimpleName())
.type(Upload.class.getName())
.uri(file)
.host("localhost")
.port("6622")
.username("foo")
.password("pass")
.rootDir(true)
.build();

return task.run(TestsUtils.mockRunContext(runContextFactory, task, ImmutableMap.of()));
}
}
8 changes: 4 additions & 4 deletions src/test/java/io/kestra/plugin/fs/sftp/TriggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ void move() throws Exception {
.port("6622")
.username("foo")
.password("pass")
.from("/upload/" + random + "/")
.from("/upload/trigger/")
.action(Downloads.Action.MOVE)
.moveDirectory("/upload/" + random + "-move/")
.moveDirectory("/upload/trigger-move/")
.build();

String out = FriendlyId.createFriendlyId();
Upload.Output upload = utils().upload("/upload/" + random + "/" + out + ".yml");
Upload.Output upload = utils().upload("/upload/trigger/" + out + ".yml");

Map.Entry<ConditionContext, TriggerContext> context = TestsUtils.mockTrigger(runContextFactory, trigger);
Optional<Execution> execution = trigger.evaluate(context.getKey(), context.getValue());
Expand Down Expand Up @@ -84,7 +84,7 @@ void move() throws Exception {
.port("6622")
.username("foo")
.password("pass")
.from("/upload/" + random + "-move/" + out + ".yml")
.from("/upload/trigger" + "-move/" + out + ".yml")
.build();

io.kestra.plugin.fs.vfs.Download.Output run = task.run(TestsUtils.mockRunContext(runContextFactory, task, ImmutableMap.of()));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/kestra/plugin/fs/sftp/UploadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMap;
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.utils.IdUtils;
import io.kestra.core.utils.TestsUtils;
import io.kestra.plugin.fs.vfs.Uploads.Output;
import io.kestra.plugin.fs.vfs.models.File;
Expand All @@ -25,8 +26,7 @@ class UploadsTest {
@Inject
private SftpUtils sftpUtils;

@Value("${kestra.variables.globals.random}")
private String random;
private final String random = IdUtils.create();

@Test
void run() throws Exception {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/io/kestra/plugin/fs/smb/SmbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.utils.TestsUtils;
import io.kestra.plugin.fs.AbstractUtils;
import io.kestra.plugin.fs.vfs.Delete;
import io.kestra.plugin.fs.vfs.List;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand Down Expand Up @@ -45,4 +46,18 @@ public List.Output list(String dir) throws Exception {
.build()
.run(this.runContextFactory.of());
}

@Override
public Delete.Output delete(String file) throws Exception {
var task = io.kestra.plugin.fs.smb.Delete.builder()
.id(SmbUtils.class.getSimpleName())
.type(SmbUtils.class.getName())
.uri(file)
.host("localhost")
.username("alice")
.password("alipass")
.build();

return task.run(TestsUtils.mockRunContext(runContextFactory, task, ImmutableMap.of()));
}
}
4 changes: 2 additions & 2 deletions src/test/java/io/kestra/plugin/fs/smb/UploadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMap;
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.utils.IdUtils;
import io.kestra.core.utils.TestsUtils;
import io.kestra.plugin.fs.vfs.models.File;
import io.micronaut.context.annotation.Value;
Expand All @@ -24,8 +25,7 @@ class UploadsTest {
@Inject
private SmbUtils smbUtils;

@Value("${kestra.variables.globals.random}")
private String random;
private final String random = IdUtils.create();

@Test
void run() throws Exception {
Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ kestra:
type: local
local:
base-path: /tmp/unittest
variables:
globals:
random: "${random.shortuuid}"
4 changes: 2 additions & 2 deletions src/test/resources/flows/ftp-listen-none-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ triggers:
port: 6621
username: guest
password: guest
from: "/upload/{{ globals.random }}-none/"
from: "/upload/trigger-none/"
interval: PT10S
action: NONE
passiveMode: true
moveDirectory: "/upload/{{ globals.random }}-move/"
moveDirectory: "/upload/trigger-move/"

tasks:
- id: end
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/flows/ftp-listen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ triggers:
port: 6621
username: guest
password: guest
from: "/upload/{{ globals.random }}/"
from: "/upload/trigger/"
interval: PT10S
action: MOVE
passiveMode: true
moveDirectory: "/upload/{{ globals.random }}-move/"
moveDirectory: "/upload/trigger-move/"

tasks:
- id: end
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/flows/sftp-listen-none-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ triggers:
port: 6622
username: foo
password: pass
from: "/upload/{{ globals.random }}-none/"
from: "/upload/trigger-none/"
interval: PT10S
action: NONE
moveDirectory: "/upload/{{ globals.random }}-move/"
moveDirectory: "/upload/trigger-move/"

tasks:
- id: end
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/flows/sftp-listen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ triggers:
port: 6622
username: foo
password: pass
from: "/upload/{{ globals.random }}/"
from: "/upload/trigger/"
interval: PT10S
action: MOVE
moveDirectory: "/upload/{{ globals.random }}-move/"
moveDirectory: "/upload/trigger-move/"

tasks:
- id: end
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/flows/smb-listen-none-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ triggers:
port: 445
username: alice
password: alipass
from: "/upload/{{ globals.random }}-none/"
from: "/upload/trigger-none/"
interval: PT10S
action: NONE
moveDirectory: "/upload/{{ globals.random }}-move/"
moveDirectory: "/upload/trigger-move/"

tasks:
- id: end
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/flows/smb-listen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ triggers:
port: 445
username: alice
password: alipass
from: "/upload/{{ globals.random }}/"
from: "/upload/trigger/"
interval: PT10S
action: MOVE
moveDirectory: "/upload/{{ globals.random }}-move/"
moveDirectory: "/upload/trigger-move/"

tasks:
- id: end
Expand Down

0 comments on commit b1cd5d7

Please sign in to comment.