Skip to content

Commit

Permalink
Merge pull request #28 from kbase/sdkdev
Browse files Browse the repository at this point in the history
Move test files into common directory pt1
  • Loading branch information
MrCreosote authored Jan 18, 2025
2 parents bfbef5f + 19893f0 commit 58dd884
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 51 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ src/java/us/kbase/mobu/git.properties
/htmlcov/
/classes/
/reports/
/temp_test/
/TestAsyncJava/
/TestAsyncPerl/
/TestAsyncPython/
/temp_test_callback/
/junit*.properties
/ASimpleModule_for_unit_testingPython/
/ASimpleModule_for_unit_testingJava/
Expand All @@ -54,4 +52,4 @@ src/java/us/kbase/mobu/git.properties
/a_SimpleModule_for_unit_testing_perl/
/ASimpleModule_for_unit_testingPythonError/
/a_SimpleModule_for_rename_unit_testing_python/
/TestDynamicServWizConfig/
/temp_kbsdkplus_test/
19 changes: 8 additions & 11 deletions src/java/us/kbase/kidl/test/KidlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -46,21 +49,15 @@
import us.kbase.kidl.KbTypedef;
import us.kbase.kidl.KidlParseException;
import us.kbase.kidl.KidlParser;
import us.kbase.scripts.test.TestConfigHelper;

public class KidlTest {
public static final String tempDirName = "temp_test";

private static File prepareWorkDir() throws IOException {
File tempDir = new File(".").getCanonicalFile();
if (!tempDir.getName().equals(tempDirName)) {
tempDir = new File(tempDir, tempDirName);
if (!tempDir.exists())
tempDir.mkdir();
}
File workDir = new File(tempDir, "test_kidl");
if (!workDir.exists())
workDir.mkdir();
return workDir;
private static File prepareWorkDir() throws Exception {
final Path workDir = Paths.get(TestConfigHelper.getTempTestDir(), "test_kidl");
Files.createDirectories(workDir);
return workDir.toFile();
}

private static List<String> getLines(String text) throws Exception {
Expand Down
13 changes: 9 additions & 4 deletions src/java/us/kbase/mobu/initializer/test/DynamicServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -32,11 +35,13 @@ public class DynamicServiceTest extends DockerClientServerTester {

@BeforeClass
public static void beforeClass() throws Exception {
// TODO TEST CLEANUP delete this directory
final File workDir = new File(SIMPLE_MODULE_NAME + "ServWizConfig");
workDir.mkdirs();
// TODO TEST CLEANUP delete this directory
final Path workDir = Paths.get(
TestConfigHelper.getTempTestDir(), SIMPLE_MODULE_NAME + "ServWizConfig"
);
Files.createDirectories(workDir);
final File cfgFile = TypeGeneratorTest.prepareDeployCfg(
workDir, SERVICE_WIZARD, "servwiz");
workDir.toFile(), SERVICE_WIZARD, "servwiz");
// needed for the service wizard mock to start up correctly
System.setProperty("KB_DEPLOYMENT_CONFIG", cfgFile.getCanonicalPath());
serviceWizardPort = TypeGeneratorTest.findFreePort();
Expand Down
12 changes: 6 additions & 6 deletions src/java/us/kbase/mobu/initializer/test/InitializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -16,6 +17,7 @@

import junit.framework.Assert;
import us.kbase.mobu.initializer.ModuleInitializer;
import us.kbase.scripts.test.TestConfigHelper;

public class InitializerTest {
private static File tempDir = null;
Expand Down Expand Up @@ -115,7 +117,7 @@ public boolean examineModule(String moduleName, boolean useExample, String langu
}

@BeforeClass
public static void prepPathsToCheck() throws IOException {
public static void prepPathsToCheck() throws Exception {
allExpectedDefaultPaths = new ArrayList<String>(Arrays.asList(EXPECTED_PATHS));
allExpectedDefaultPaths.addAll(Arrays.asList(EXPECTED_DEFAULT_PATHS));
allExpectedDefaultPaths.add(SIMPLE_MODULE_NAME + ".spec");
Expand Down Expand Up @@ -153,11 +155,9 @@ public static void prepPathsToCheck() throws IOException {
rPaths.add("ui/narrative/methods/" + EXAMPLE_OLD_METHOD_NAME + "/spec.json");
rPaths.add("ui/narrative/methods/" + EXAMPLE_OLD_METHOD_NAME + "/display.yaml");

File rootTemp = new File("temp_test");
if (!rootTemp.exists()) {
rootTemp.mkdir();
}
tempDir = Files.createTempDirectory(rootTemp.toPath(), "init_test_").toFile();
final Path rootTemp = Paths.get(TestConfigHelper.getTempTestDir());
Files.createDirectories(rootTemp);
tempDir = Files.createTempDirectory(rootTemp, "init_test_").toFile();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

import junit.framework.Assert;
Expand All @@ -20,8 +22,11 @@ public class ClientInstallerTest {

@BeforeClass
public static void prepareClass() throws Exception {
File rootTemp = new File("temp_test");
tempDir = Files.createTempDirectory(rootTemp.toPath(), "test_install_").toFile();
final Path rootTemp = Paths.get(
TestConfigHelper.getTempTestDir(), ClientInstallerTest.class.getSimpleName()
);
Files.createDirectories(rootTemp);
tempDir = Files.createTempDirectory(rootTemp, "test_install_").toFile();
}

@AfterClass
Expand Down
7 changes: 5 additions & 2 deletions src/java/us/kbase/mobu/installer/test/DepsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

Expand All @@ -19,15 +20,17 @@
import us.kbase.mobu.installer.ClientInstaller;
import us.kbase.mobu.installer.Dependency;
import us.kbase.mobu.util.DiskFileSaver;
import us.kbase.scripts.test.TestConfigHelper;

public class DepsTest {
private static File tempDir = null;
private static File depsFile = null;

@BeforeClass
public static void prepareClass() throws Exception {
File rootTemp = new File("temp_test");
tempDir = Files.createTempDirectory(rootTemp.toPath(), "test_deps_").toFile();
tempDir = Files.createTempDirectory(
Paths.get(TestConfigHelper.getTempTestDir()), "test_deps_"
).toFile();
depsFile = new File(tempDir, "dependencies.json");
}

Expand Down
13 changes: 11 additions & 2 deletions src/java/us/kbase/mobu/tester/test/CallbackServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ public class CallbackServerTest {

// TODO TEST replace java CBS with the python ver. Should get these tests to pass against it

private static final Path TEST_DIR = Paths.get("temp_test_callback");

private static final Path TEST_DIR;
static {
try {
TEST_DIR = Paths.get(
TestConfigHelper.getTempTestDir(), CallbackServerTest.class.getSimpleName()
);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

private static AuthToken token;
private static CatalogClient CAT_CLI;

Expand Down
12 changes: 8 additions & 4 deletions src/java/us/kbase/scripts/test/TestConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public static void init() throws Exception {
initialized = true;
}

public static String getTestConfigParam(String param, boolean required) throws Exception {
private static String getTestConfigParam(String param, boolean required) throws Exception {
if (!initialized) {
init();
}
String ret = System.getProperty(param);
if (required && ret == null) {
throw new IllegalStateException("Parameter [" + param + "] is not set " +
"in test configuraion. Please check test_scripts/test.cfg file");
"in test configuration. Please check test.cfg file");
}
return ret;
}

public static String getTestConfigParam(String param, String defaultValue) throws Exception {
private static String getTestConfigParam(String param, String defaultValue) throws Exception {
String ret = getTestConfigParam(param, false);
return ret == null ? defaultValue : ret;
}
Expand All @@ -51,7 +51,7 @@ public static String getAuthServiceUrlInsecure() throws Exception {
return getTestConfigParam("test.auth-service-url-allow-insecure", "false");
}

public static ConfigurableAuthService getAuthService() throws Exception {
private static ConfigurableAuthService getAuthService() throws Exception {
return new ConfigurableAuthService(
new AuthConfig().withKBaseAuthServerURL(new URL(getAuthServiceUrl()))
.withAllowInsecureURLs("true".equals(getAuthServiceUrlInsecure())));
Expand All @@ -78,4 +78,8 @@ public static AuthToken getToken2() throws Exception {
public static String getKBaseEndpoint() throws Exception {
return getTestConfigParam("test.kbase.endpoint", true);
}

public static String getTempTestDir() throws Exception {
return getTestConfigParam("test.temp.dir", true);
}
}
40 changes: 23 additions & 17 deletions src/java/us/kbase/scripts/test/TypeGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import java.net.ServerSocket;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -75,11 +78,10 @@ public class TypeGeneratorTest extends Assert {
// the running service
//TODO TESTING pep8 test? Not really sure about this.

public static final String rootPackageName = "us.kbase";
public static final String tempDirName = "temp_test";
public static final String SERVICE_WIZARD = "ServiceWizard";
private static final String rootPackageName = "us.kbase";
private static final String SERVICE_WIZARD = "ServiceWizard";

public static boolean debugClientTimes = false;
private static boolean debugClientTimes = false;

public static void main(String[] args) throws Exception{
int testNum = Integer.parseInt(args[0]);
Expand Down Expand Up @@ -660,7 +662,8 @@ protected static void runPythonServerTest(
"cd \"" + serverOutDir.getAbsolutePath() + "\"",
"if [ ! -d biokbase ]; then",
" mkdir -p ./biokbase",
" cp -r ../../../src/java/us/kbase/templates/log.py ./biokbase/",
// TODO TESTCODE this is bonkers, need a better way of reffing files
" cp -r ../../../../src/java/us/kbase/templates/log.py ./biokbase/",
"fi"
));
if (serverPortNum != null) {
Expand Down Expand Up @@ -993,22 +996,24 @@ private static URLClassLoader prepareUrlClassLoader(File libDir, File binDir)
return urlcl;
}

private static File prepareWorkDir(int testNum) throws IOException {
File tempDir = new File(".").getCanonicalFile();
if (!tempDir.getName().equals(tempDirName)) {
tempDir = new File(tempDir, tempDirName);
if (!tempDir.exists())
tempDir.mkdir();
}
for (File dir : tempDir.listFiles()) {
private static File prepareWorkDir(int testNum) throws Exception {
final Path tempDir = Paths.get(
TestConfigHelper.getTempTestDir(), TypeGeneratorTest.class.getSimpleName()
);
Files.createDirectories(tempDir);
for (File dir : tempDir.toFile().listFiles()) {
if (dir.isDirectory() && dir.getName().startsWith("test" + testNum + "_"))
try {
TextUtils.deleteRecursively(dir);
} catch (Exception e) {
System.out.println("Can not delete directory [" + dir.getName() + "]: " + e.getMessage());
System.out.println(
"Can not delete directory [" + dir.getName() + "]: " + e.getMessage()
);
}
}
File workDir = new File(tempDir, "test" + testNum + "_" + System.currentTimeMillis());
final File workDir = new File(
tempDir.toFile(), "test" + testNum + "_" + System.currentTimeMillis()
);
if (!workDir.exists())
workDir.mkdir();
return workDir;
Expand Down Expand Up @@ -1067,7 +1072,7 @@ private static void runJavaClientTest(int testNum, String testPackage, JavaData
try {
testClass.getConstructor(clientClass).newInstance(client);
} catch (NoSuchMethodException e) {
testClass.getConstructor(clientClass, Integer.class).newInstance(client, portNum);
testClass.getConstructor(clientClass, Integer.class).newInstance(client, portNum);
}
} else {
try {
Expand Down Expand Up @@ -1145,7 +1150,8 @@ private static void runPythonClientTest(int testNum, String testPackage, JavaDat
if (ver3)
lines.add("export PYTHONPATH=");
lines.addAll(Arrays.asList(
pyCmd + " ../../../test_scripts/python/test_client.py -t " + configFile.getName() +
// TODO TESTCODE need a better way of referencing the test code, this is dumb
pyCmd + " ../../../../test_scripts/python/test_client.py -t " + configFile.getName() +
" -e http://localhost:" + portNum +
" -o \"" + System.getProperty("test.token") + "\"" +
(System.getProperty("KB_JOB_CHECK_WAIT_TIME") == null ? "" :
Expand Down
3 changes: 3 additions & 0 deletions test.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ test.token2=
test.kbase.endpoint=https://ci.kbase.us/services
test.auth-service-url=https://ci.kbase.us/services/auth/api/legacy/KBase/Sessions/Login
test.auth-service-url-allow-insecure=false

# A temporary directory for storing test files
test.temp.dir=temp_kbsdkplus_test

0 comments on commit 58dd884

Please sign in to comment.