Skip to content

Commit

Permalink
✅ YarnDriver tests were added
Browse files Browse the repository at this point in the history
  • Loading branch information
noyshabtay committed Nov 15, 2023
1 parent 911ae50 commit 927c2b5
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/test/java/com/jfrog/ide/common/yarn/YarnDriverTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.jfrog.ide.common.yarn;

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

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

import static org.testng.Assert.*;

/**
* Test the 'why' functionality in YarnDriver.
*/
public class YarnDriverTest {
private static final Path YARN_ROOT = Paths.get(".").toAbsolutePath().normalize().resolve(Paths.get("src", "test", "resources", "yarn"));

enum Project {

EMPTY("empty"),
DEPENDENCY("dependency");

private final Path path;

Project(String path) {
this.path = YARN_ROOT.resolve(path);
}
}

private final YarnDriver yarnDriver = new YarnDriver(null);
private File tempProject;

@BeforeMethod
public void setUp(Object[] testArgs) {
try {
tempProject = Files.createTempDirectory("ide-plugins-common-yarn").toFile();
tempProject.deleteOnExit();
FileUtils.copyDirectory(((Project) testArgs[0]).path.toFile(), tempProject);
} catch (IOException e) {
fail(e.getMessage(), e);
}
}

@AfterMethod
public void tearDown() {
FileUtils.deleteQuietly(tempProject);
}

@DataProvider
private Object[][] yarnWhyProvider() {
return new Object[][]{
{Project.DEPENDENCY, "progress"},
{Project.DEPENDENCY, "has-flag"},
{Project.EMPTY, "component-name"} // Should return an error
};
}

@Test(dataProvider = "yarnWhyProvider")
public void yarnWhyTest(Project project, String componentName) {
try {
JsonNode[] whyResults = yarnDriver.why(tempProject, componentName);
assertNotNull(whyResults);
assertTrue(whyResults.length > 0);

if (project == Project.EMPTY) {
assertTrue(whyResults[0].has("problems"), "Yarn why command result should contain problems:\n" + whyResults[0].toString());
return;
}

for (JsonNode result : whyResults) {
assertNotNull(result);
assertFalse(result.has("problems"), "Unexpected problems in yarn why command result:\n" + result.get("problems"));
}
} catch (IOException e) {
fail("Exception during yarn why command: " + e.getMessage(), e);
}
}
}

0 comments on commit 927c2b5

Please sign in to comment.