Skip to content

Commit

Permalink
Delay launchdir init until test execution (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuhlich authored May 12, 2024
1 parent 9dafa52 commit c2734d9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
31 changes: 21 additions & 10 deletions src/main/java/com/askimed/nf/test/core/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,26 @@ public File getConfig() {
return config;
}

@Override
public void setup(Config config, File testDirectory) throws IOException {
public void defineDirectories(File testDirectory) throws IOException {

if (testDirectory == null) {
throw new IOException("Testcase setup failed: No home directory set");
}

launchDir = initDirectory("Launch Directory", testDirectory, DIRECTORY_TESTS, getHash());
metaDir = initDirectory("Meta Directory", launchDir, DIRECTORY_META);
outputDir = initDirectory("Output Directory", launchDir, DIRECTORY_OUTPUT);
workDir = initDirectory("Working Directory", launchDir, DIRECTORY_WORK);
launchDir = constructDirectory(testDirectory, DIRECTORY_TESTS, getHash());
metaDir = constructDirectory(launchDir, DIRECTORY_META);
outputDir = constructDirectory(launchDir, DIRECTORY_OUTPUT);
workDir = constructDirectory(launchDir, DIRECTORY_WORK);

}

@Override
public void setup(Config config) throws IOException {

initDirectory("Launch Directory", launchDir);
initDirectory("Meta Directory", metaDir);
initDirectory("Output Directory", outputDir);
initDirectory("Working Directory", workDir);
FileStaging[] sharedDirectories = new FileStaging[]{
new FileStaging("bin", config != null ? config.getStageMode() : FileStaging.MODE_COPY),
new FileStaging("lib", config != null ? config.getStageMode() : FileStaging.MODE_COPY),
Expand Down Expand Up @@ -136,15 +145,17 @@ public void execute() throws Throwable {
}
}

public File initDirectory(String name, File root, String... childs) throws IOException {

public File constructDirectory(File root, String... childs) {
String path = FileUtil.path(root.getAbsolutePath(), FileUtil.path(childs));

File directory = new File(path).getAbsoluteFile();
return directory;
}

public void initDirectory(String name, File directory) throws IOException {

try {
FileUtil.deleteDirectory(directory);
FileUtil.createDirectory(directory);
return directory;
} catch (Exception e) {
throw new IOException(name + " '" + directory + "' could not be deleted or created:\n" + e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ public void evalualteTestClosures() throws Throwable {
Closure closure = namedClosure.closure;

ITest test = getNewTestInstance(testName);
test.setup(config, getHomeDirectory());
test.defineDirectories(getHomeDirectory());
closure.setDelegate(test);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.call();
addTest(test);
}
}

public void setupTest(ITest test) throws Throwable {
test.setup(config);
}


protected abstract ITest getNewTestInstance(String name);

public void setScript(String script) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/askimed/nf/test/core/ITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

public interface ITest extends ITaggable {

public void setup(Config config, File homeDirectory) throws Throwable;
public void defineDirectories(File testDirectory) throws Throwable;

public void setup(Config config) throws Throwable;

public void execute() throws Throwable;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/askimed/nf/test/core/ITestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface ITestSuite extends ITaggable {

public void evalualteTestClosures() throws Throwable;

}
public void setupTest(ITest test) throws Throwable;

}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ public int execute() throws Throwable {
log.info("Run test '{}'. type: {}", test, test.getClass().getName());
totalTests++;

testSuite.setupTest(test);

listener.executionStarted(test);
TestExecutionResult result = new TestExecutionResult(test);
test.setWithTrace(withTrace);
Expand Down

0 comments on commit c2734d9

Please sign in to comment.