Skip to content

Commit 4ded98f

Browse files
committed
Refix tests leaving undeletable files on disk
1 parent c29f049 commit 4ded98f

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

src/java/us/kbase/mobu/tester/test/ModuleTesterTest.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import java.io.File;
88
import java.nio.file.Path;
99
import java.nio.file.Paths;
10-
import java.util.HashMap;
11-
import java.util.Map;
12-
import java.util.Map.Entry;
10+
import java.util.LinkedList;
11+
import java.util.List;
1312

1413
import junit.framework.Assert;
1514

@@ -33,7 +32,7 @@ public class ModuleTesterTest {
3332
private static final String SIMPLE_MODULE_NAME = "ASimpleModule_for_unit_testing";
3433
private static final boolean DELETE_TEST_MODULES = true;
3534

36-
private static final Map<Path, Boolean> CREATED_MODULES = new HashMap<>();
35+
private static final List<Path> CREATED_MODULES = new LinkedList<>();
3736
private static AuthToken token;
3837

3938
@BeforeClass
@@ -43,9 +42,8 @@ public static void beforeClass() throws Exception {
4342

4443
@AfterClass
4544
public static void tearDownModule() throws Exception {
46-
for (final Entry<Path, Boolean> dirAndCov : CREATED_MODULES.entrySet()) {
47-
TestUtils.deleteTestModule(
48-
dirAndCov.getKey(), dirAndCov.getValue(), DELETE_TEST_MODULES);
45+
for (final Path mod: CREATED_MODULES) {
46+
TestUtils.deleteTestModule(mod, true, DELETE_TEST_MODULES);
4947
}
5048
}
5149

@@ -55,14 +53,9 @@ public void afterTest() {
5553
}
5654

5755
private Path init(final String lang, final String moduleName) throws Exception {
58-
return init(lang, moduleName, false);
59-
}
60-
61-
private Path init(final String lang, final String moduleName, final boolean hasPyCov)
62-
throws Exception {
6356
final Path workDir = Paths.get(TestConfigHelper.getTempTestDir(), moduleName);
64-
TestUtils.deleteTestModule(workDir, hasPyCov, true);
65-
CREATED_MODULES.put(workDir, hasPyCov);
57+
TestUtils.deleteTestModule(workDir, true, true);
58+
CREATED_MODULES.add(workDir);
6659
new ModuleInitializer(
6760
moduleName,
6861
token.getUserName(),
@@ -105,7 +98,7 @@ public void testPythonModuleExample() throws Exception {
10598
System.out.println("Test [testPythonModuleExample]");
10699
String lang = "python";
107100
String moduleName = SIMPLE_MODULE_NAME + "Python";
108-
final Path moduleDir = init(lang, moduleName, true);
101+
final Path moduleDir = init(lang, moduleName);
109102
// TODO TESTHACK remove this when there's a base image that deploys the authclient correctly
110103
FileUtils.copyFile(
111104
new File("./src/java/us/kbase/templates/authclient.py"),
@@ -133,7 +126,7 @@ public void testPythonModuleError() throws Exception {
133126
System.out.println("Test [testPythonModuleError]");
134127
String lang = "python";
135128
String moduleName = SIMPLE_MODULE_NAME + "PythonError";
136-
final Path moduleDir = init(lang, moduleName, true);
129+
final Path moduleDir = init(lang, moduleName);
137130
final Path implFile = moduleDir.resolve(
138131
Paths.get("lib", moduleName, moduleName + "Impl.py")
139132
);
@@ -188,7 +181,7 @@ public void testSelfCalls() throws Exception {
188181
String moduleName = SIMPLE_MODULE_NAME + "Self";
189182
final Path workDir = Paths.get(TestConfigHelper.getTempTestDir(), moduleName);
190183
TestUtils.deleteTestModule(workDir, true, true);
191-
CREATED_MODULES.put(workDir, true);
184+
CREATED_MODULES.add(workDir);
192185
String implInit = "" +
193186
"#BEGIN_HEADER\n" +
194187
"import os\n"+

src/java/us/kbase/test/sdk/TestUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ public static void makeDockerOutputWritable(
5454

5555
/** Delete an SDK module. Does nothing if the module path doesn't exist or isn't a directory.
5656
* @param module the path to the module root.
57-
* @param hasPyCov true if the module is expected to have root owned coverage data
58-
* in test_local/test_coverage, which will be set to world writable depending on the
57+
* @param makeWriteable true if the module is expected to have root owned data
58+
* in test_local/workdir, which will be set to world writable depending on the
5959
* test configuration file.
6060
* @param deleteModule if false, the module won't be deleted.
6161
* @throws Exception if an error occurs
6262
*/
6363
public static void deleteTestModule(
6464
final Path module,
65-
boolean hasPyCov,
65+
boolean makeWriteable,
6666
boolean deleteModule)
6767
throws Exception {
6868
if (Files.exists(module) && Files.isDirectory(module)) {
69-
if (TestConfigHelper.getMakeRootOwnedFilesWriteable() && hasPyCov) {
70-
TestUtils.makeDockerOutputWritable(module, Paths.get("test_coverage"), true);
69+
if (TestConfigHelper.getMakeRootOwnedFilesWriteable() && makeWriteable) {
70+
TestUtils.makeDockerOutputWritable(module, Paths.get("."), true);
7171
}
7272
if (deleteModule) {
7373
try {

0 commit comments

Comments
 (0)