Skip to content

Commit 1c3a4f0

Browse files
Check for cloud=docker for skipping tests
1 parent 429719d commit 1c3a4f0

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

Diff for: cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ public void execute() {
361361
this.outStream.println("WARNING: Test report generation is not supported with Ballerina cloud test");
362362
}
363363

364+
boolean isTestingDelegated = project.buildOptions().cloud().equals("docker");
364365

365366
// Run pre-build tasks to have the project reloaded.
366367
// In code coverage generation, the module map is duplicated.
@@ -369,7 +370,7 @@ public void execute() {
369370
// Hence, below tasks are executed before extracting the module map from the project.
370371
TaskExecutor preBuildTaskExecutor = new TaskExecutor.TaskBuilder()
371372
.addTask(new CleanTargetCacheDirTask(), isSingleFile) // clean the target cache dir(projects only)
372-
.addTask(new CleanTargetBinTestsDirTask(), (isSingleFile || project.buildOptions().cloud().isEmpty()))
373+
.addTask(new CleanTargetBinTestsDirTask(), (isSingleFile || !isTestingDelegated))
373374
.addTask(new RunBuildToolsTask(outStream), isSingleFile) // run build tools
374375
.build();
375376
preBuildTaskExecutor.executeTasks(project);
@@ -391,16 +392,14 @@ public void execute() {
391392
isPackageModified, buildOptions.enableCache()))
392393
// .addTask(new CopyResourcesTask(), listGroups) // merged with CreateJarTask
393394
.addTask(new CreateTestExecutableTask(outStream, groupList, disableGroupList, testList, listGroups,
394-
cliArgs, isParallelExecution),
395-
project.buildOptions().cloud().isEmpty())
395+
cliArgs, isParallelExecution), !isTestingDelegated)
396396
.addTask(new RunTestsTask(outStream, errStream, rerunTests, groupList, disableGroupList,
397397
testList, includes, coverageFormat, moduleMap, listGroups, excludes, cliArgs,
398398
isParallelExecution),
399-
(project.buildOptions().nativeImage() ||
400-
!project.buildOptions().cloud().isEmpty()))
399+
(project.buildOptions().nativeImage() || isTestingDelegated))
401400
.addTask(new RunNativeImageTestTask(outStream, rerunTests, groupList, disableGroupList,
402401
testList, includes, coverageFormat, moduleMap, listGroups, isParallelExecution),
403-
(!project.buildOptions().nativeImage() || !project.buildOptions().cloud().isEmpty()))
402+
(!project.buildOptions().nativeImage() || isTestingDelegated))
404403
.addTask(new DumpBuildTimeTask(outStream), !project.buildOptions().dumpBuildTime())
405404
.build();
406405

Diff for: cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunTestsTask.java

-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ public RunTestsTask(PrintStream out, PrintStream err, boolean rerunTests, String
142142
public void execute(Project project) {
143143
long start = 0;
144144

145-
//do not execute if cloud option is given, we only use the object to use the properties and methods in it
146-
if (!project.buildOptions().cloud().isEmpty()) {
147-
return;
148-
}
149-
150145
if (project.buildOptions().dumpBuildTime()) {
151146
start = System.currentTimeMillis();
152147
}

Diff for: cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/TestCommandTest.java

+29-6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput;
6262
import static io.ballerina.cli.cmd.CommandOutputUtils.readFileAsString;
6363
import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent;
64+
import static io.ballerina.cli.cmd.CommandUtil.USER_HOME;
6465
import static io.ballerina.cli.utils.OsUtils.isWindows;
6566
import static io.ballerina.projects.util.ProjectConstants.BUILD_FILE;
6667
import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML;
@@ -433,13 +434,35 @@ public void testTestEmptyProjectWithBuildTools() throws IOException {
433434
Assert.assertEquals(buildLog.replace("\r", ""), getOutput("test-empty-project-with-build-tools.txt"));
434435
}
435436

436-
@Test(description = "Test the emission of testable fat jar for a project with tests")
437+
@Test(description = "Test --cloud=k8s flag with a project with tests")
438+
public void testTestWithCloudK8s() throws IOException {
439+
Path projectPath = this.testResources.resolve("validProjectWithTests");
440+
ProjectUtils.deleteDirectory(projectPath.resolve("target"));
441+
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
442+
Path mockedLocalRepo = this.testResources.resolve("mocked-local-repo");
443+
System.setProperty(USER_HOME, mockedLocalRepo.toString());
444+
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
445+
new CommandLine(testCommand).parseArgs("--cloud=k8s");
446+
testCommand.execute();
447+
448+
String buildLog = readOutput(true);
449+
Assert.assertEquals(buildLog.replace("\r", ""), getOutput("test-project.txt"));
450+
451+
Path targetDir = projectPath.resolve("target");
452+
Path testableJar = targetDir.resolve("bin/tests/winery-testable.jar");
453+
Assert.assertFalse(Files.exists(testableJar));
454+
Path mainArgsFile = testableJar.getParent().resolve(TEST_RUNTIME_MAIN_ARGS_FILE);
455+
Assert.assertFalse(Files.exists(mainArgsFile));
456+
}
457+
458+
@Test(description = "Test the emission of testable fat jar for a project with tests",
459+
dependsOnMethods = "testTestWithCloudK8s")
437460
public void testTestableFatJarEmission() {
438461
Path projectPath = this.testResources.resolve("validProjectWithTests");
439462
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
440463

441464
Path mockedLocalRepo = this.testResources.resolve("mocked-local-repo");
442-
System.setProperty("user.home", mockedLocalRepo.toString());
465+
System.setProperty(USER_HOME, mockedLocalRepo.toString());
443466

444467
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
445468
new CommandLine(testCommand).parseArgs("--cloud=docker");
@@ -494,7 +517,7 @@ public void testEmissionOfTestableFatJarForProjectWithMocking() throws IOExcepti
494517
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
495518

496519
Path mockedLocalRepo = this.testResources.resolve("mocked-local-repo");
497-
System.setProperty("user.home", mockedLocalRepo.toString());
520+
System.setProperty(USER_HOME, mockedLocalRepo.toString());
498521

499522
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
500523
new CommandLine(testCommand).parseArgs("--cloud=docker");
@@ -556,7 +579,7 @@ public void testEmissionOfSingleFatJarForCloudAndGraalVM() throws IOException {
556579
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
557580

558581
Path mockedLocalRepo = this.testResources.resolve("mocked-local-repo");
559-
System.setProperty("user.home", mockedLocalRepo.toString());
582+
System.setProperty(USER_HOME, mockedLocalRepo.toString());
560583

561584
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
562585
new CommandLine(testCommand).parseArgs("--cloud=docker", "--graalvm");
@@ -580,7 +603,7 @@ public void testEmissionOfMultipleFatJarsForProjectWithMockingForCloudAndGraalVM
580603
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
581604

582605
Path mockedLocalRepo = this.testResources.resolve("mocked-local-repo");
583-
System.setProperty("user.home", mockedLocalRepo.toString());
606+
System.setProperty(USER_HOME, mockedLocalRepo.toString());
584607

585608
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
586609
new CommandLine(testCommand).parseArgs("--cloud=docker", "--graalvm");
@@ -654,7 +677,7 @@ public void testEmissionOfTestableFatJarForSingleTestBalFile() {
654677
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
655678

656679
Path mockedLocalRepo = this.testResources.resolve("mocked-local-repo");
657-
System.setProperty("user.home", mockedLocalRepo.toString());
680+
System.setProperty(USER_HOME, mockedLocalRepo.toString());
658681

659682
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
660683
new CommandLine(testCommand).parseArgs("--cloud=docker", "main_tests.bal");

Diff for: misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/TestProcessor.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private TestSuite generateTestSuite(Module module, JarResolver jarResolver) {
154154
}
155155

156156
// If not a cloud build, add the test execution dependencies
157-
if (module.project().buildOptions().cloud().isEmpty()) {
157+
if (!areTestsDelegated(module)) {
158158
addTestExecutionDependencies(module, jarResolver, testSuite);
159159
} else if (module.project().buildOptions().nativeImage()) {
160160
// If it is a cloud build, add the test execution dependencies only if native image is enabled
@@ -183,7 +183,7 @@ private TestSuite createTestSuite(Module module, String testModuleName) {
183183
module.descriptor().name().toString(), testSuite);
184184
testSuite.setPackageName(module.descriptor().packageName().toString());
185185

186-
if (module.project().buildOptions().cloud().isEmpty()) {
186+
if (!areTestsDelegated(module)) {
187187
testSuite.setSourceRootPath(module.project().sourceRoot().toString());
188188
} else {
189189
testSuite.setSourceRootPath("./");
@@ -615,4 +615,8 @@ private String getExecutePath(Module module) {
615615
//TODO: Throw an exception for not generating the test execution file. Currently, this handles at BTestRunner
616616
return executePath;
617617
}
618+
619+
private boolean areTestsDelegated(Module module) {
620+
return module.project().buildOptions().cloud().equals("docker");
621+
}
618622
}

0 commit comments

Comments
 (0)