Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay launchdir init until test execution #214

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading