use of com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor in project synopsys-detect by blackducksoftware.
the class DetectableFactory method goModCliExtractor.
private GoModCliExtractor goModCliExtractor(GoModCliDetectableOptions options) {
GoModCommandRunner goModCommandRunner = new GoModCommandRunner(executableRunner);
GoListParser goListParser = new GoListParser(gson);
GoGraphParser goGraphParser = new GoGraphParser();
GoModWhyParser goModWhyParser = new GoModWhyParser();
GoVersionParser goVersionParser = new GoVersionParser();
GoModGraphGenerator goModGraphGenerator = new GoModGraphGenerator(externalIdFactory);
return new GoModCliExtractor(goModCommandRunner, goListParser, goGraphParser, goModWhyParser, goVersionParser, goModGraphGenerator, externalIdFactory, options.getExcludedDependencyTypes());
}
use of com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor in project synopsys-detect by blackducksoftware.
the class GoModCliExtractorTest method handleMultipleReplacementsForOneComponentTest.
// These tests weren't updated to use the new json format for go the first call of go list, yet somehow still passing?
// With the removal of -u, Mockito kept returning null for that first go list call instead of ExecutableOutput.
// I think this test is redundant with the existence of GoModDetectableMinusWhyTest
// Leaving it here for now to review one day. JM-01/2022
@Test
public void handleMultipleReplacementsForOneComponentTest() throws ExecutableRunnerException, ExecutableFailedException, DetectableException {
DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
File directory = new File("");
ExecutableTarget goExe = ExecutableTarget.forFile(new File(""));
Answer<ExecutableOutput> executableAnswer = new Answer<ExecutableOutput>() {
String[] goListArgs = { "list", "-m", "-json" };
String[] goListJsonArgs = { "list", "-m", "-json", "all" };
String[] goModGraphArgs = { "mod", "graph" };
@Override
public ExecutableOutput answer(InvocationOnMock invocation) {
Executable executable = invocation.getArgument(0, Executable.class);
List<String> commandLine = executable.getCommandWithArguments();
ExecutableOutput result = null;
if (commandLine.containsAll(Arrays.asList(goListJsonArgs))) {
result = goListJsonOutput();
} else if (commandLine.containsAll(Arrays.asList(goListArgs))) {
result = goListOutput();
} else if (commandLine.containsAll(Arrays.asList(goModGraphArgs))) {
result = goModGraphOutput();
} else {
result = new ExecutableOutput(0, "", "");
}
return result;
}
};
GoModCliExtractor goModCliExtractor = buildGoModCliExtractor(executableRunner, executableAnswer);
boolean wasSuccessful = true;
Extraction extraction = goModCliExtractor.extract(directory, goExe);
if (extraction.getError() instanceof ArrayIndexOutOfBoundsException) {
wasSuccessful = false;
}
Assertions.assertTrue(wasSuccessful);
}
use of com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor in project synopsys-detect by blackducksoftware.
the class GoModCliExtractorTest method handleGoModWhyExceptionTest.
@Test
public void handleGoModWhyExceptionTest() throws ExecutableRunnerException, ExecutableFailedException, DetectableException {
DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
File directory = new File("");
ExecutableTarget goExe = ExecutableTarget.forFile(new File(""));
Answer<ExecutableOutput> executableAnswer = new Answer<ExecutableOutput>() {
String[] goListArgs = { "list", "-m", "-json" };
String[] goListJsonArgs = { "list", "-m", "-json", "all" };
String[] goModGraphArgs = { "mod", "graph" };
String[] goModWhyArgs = { "mod", "why", "-m", "all" };
@Override
public ExecutableOutput answer(InvocationOnMock invocation) throws Throwable {
Executable executable = invocation.getArgument(0, Executable.class);
List<String> commandLine = executable.getCommandWithArguments();
ExecutableOutput result = null;
if (commandLine.containsAll(Arrays.asList(goListJsonArgs))) {
result = goListJsonOutput();
} else if (commandLine.containsAll(Arrays.asList(goListArgs))) {
result = goListOutput();
} else if (commandLine.containsAll(Arrays.asList(goModGraphArgs))) {
result = goModGraphOutput();
} else if (commandLine.containsAll(Arrays.asList(goModWhyArgs))) {
throw new ExecutableRunnerException(new DetectableException("Unit Test Go Mod Why error"));
} else {
result = new ExecutableOutput(0, "", "");
}
return result;
}
};
GoModCliExtractor goModCliExtractor = buildGoModCliExtractor(executableRunner, executableAnswer);
boolean wasSuccessful = true;
Extraction extraction = goModCliExtractor.extract(directory, goExe);
if (extraction.getError() instanceof ArrayIndexOutOfBoundsException) {
wasSuccessful = false;
}
Assertions.assertTrue(wasSuccessful);
}
use of com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor in project synopsys-detect by blackducksoftware.
the class GoModCliExtractorTest method buildGoModCliExtractor.
private GoModCliExtractor buildGoModCliExtractor(DetectableExecutableRunner executableRunner, Answer<ExecutableOutput> executableAnswer) throws ExecutableRunnerException {
Mockito.doAnswer(executableAnswer).when(executableRunner).execute(Mockito.any(Executable.class));
GoModWhyParser goModWhyParser = new GoModWhyParser();
GoVersionParser goVersionParser = new GoVersionParser();
GoModCommandRunner goModCommandRunner = new GoModCommandRunner(executableRunner);
GoModGraphGenerator goModGraphGenerator = new GoModGraphGenerator(new ExternalIdFactory());
GoListParser goListParser = new GoListParser(new GsonBuilder().create());
GoGraphParser goGraphParser = new GoGraphParser();
ExternalIdFactory externalIdFactory = new ExternalIdFactory();
return new GoModCliExtractor(goModCommandRunner, goListParser, goGraphParser, goModWhyParser, goVersionParser, goModGraphGenerator, externalIdFactory, GoModDependencyType.UNUSED);
}
Aggregations