Search in sources :

Example 11 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class ApkPackageManagerTest method canParseArchitecture.

@Test
public void canParseArchitecture() throws ExecutableRunnerException {
    final String exampleOutput = "x86_64\n";
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(null, "apk", Arrays.asList("info", "--print-arch"))).thenReturn(new ExecutableOutput(0, exampleOutput, ""));
    ApkArchitectureResolver architectureResolver = new ApkArchitectureResolver();
    Optional<String> architecture = architectureResolver.resolveArchitecture(new ClangPackageManagerInfoFactory().apk(), null, executableRunner);
    assertTrue(architecture.isPresent());
    Assertions.assertEquals("x86_64", architecture.get());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ApkArchitectureResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.ApkArchitectureResolver) Test(org.junit.jupiter.api.Test)

Example 12 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class ClangDetectableTest method testApplicable.

@Test
public void testApplicable() {
    DetectableExecutableRunner executableRunner = null;
    List<ClangPackageManager> availablePackageManagers = new ArrayList<>(0);
    ClangExtractor clangExtractor = null;
    ClangPackageManagerRunner packageManagerRunner = null;
    ClangDetectableOptions options = new ClangDetectableOptions(false);
    DetectableEnvironment environment = MockDetectableEnvironment.empty();
    FileFinder fileFinder = MockFileFinder.withFileNamed(JSON_COMPILATION_DATABASE_FILENAME);
    ClangDetectable detectable = new ClangDetectable(environment, executableRunner, fileFinder, availablePackageManagers, clangExtractor, options, packageManagerRunner);
    assertTrue(detectable.applicable().getPassed());
}
Also used : ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) ClangExtractor(com.synopsys.integration.detectable.detectables.clang.ClangExtractor) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ClangPackageManagerRunner(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner) ClangDetectable(com.synopsys.integration.detectable.detectables.clang.ClangDetectable) ArrayList(java.util.ArrayList) MockFileFinder(com.synopsys.integration.detectable.util.MockFileFinder) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ClangDetectableOptions(com.synopsys.integration.detectable.detectables.clang.ClangDetectableOptions) MockDetectableEnvironment(com.synopsys.integration.detectable.util.MockDetectableEnvironment) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Example 13 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class PubDepsExtractorTest method testGracefulFailure.

private void testGracefulFailure(ExecutableOutput mockExecutableOutput) throws ExecutableRunnerException {
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(Mockito.any())).thenReturn(mockExecutableOutput);
    PubDepsExtractor extractor = new PubDepsExtractor(executableRunner, new PubDepsParser(), null, new ToolVersionLogger(executableRunner));
    Extraction extraction = extractor.extract(null, null, null, new DartPubDepsDetectableOptions(EnumListFilter.excludeNone()), null);
    Assertions.assertFalse(extraction.isSuccess() && null == extraction.getError());
}
Also used : PubDepsParser(com.synopsys.integration.detectable.detectables.dart.pubdep.PubDepsParser) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) DartPubDepsDetectableOptions(com.synopsys.integration.detectable.detectables.dart.pubdep.DartPubDepsDetectableOptions) PubDepsExtractor(com.synopsys.integration.detectable.detectables.dart.pubdep.PubDepsExtractor) Extraction(com.synopsys.integration.detectable.extraction.Extraction) ToolVersionLogger(com.synopsys.integration.detectable.util.ToolVersionLogger)

Example 14 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class DockerExtractorTest method getDetectableExecutableRunner.

@NotNull
private DetectableExecutableRunner getDetectableExecutableRunner() throws ExecutableRunnerException {
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    ExecutableOutput executableOutput = Mockito.mock(ExecutableOutput.class);
    Mockito.when(executableOutput.getReturnCode()).thenReturn(0);
    Mockito.when(executableRunner.execute(Mockito.any(Executable.class))).thenReturn(executableOutput);
    return executableRunner;
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Executable(com.synopsys.integration.executable.Executable) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class DockerExtractorTest method testExtractImageReturningContainerFileSystem.

@Test
@DisabledOnOs(WINDOWS)
public void testExtractImageReturningContainerFileSystem() throws ExecutableRunnerException, IOException {
    final String image = "ubuntu:latest";
    String imageId = null;
    String tar = null;
    DetectableExecutableRunner executableRunner = getDetectableExecutableRunner();
    Extraction extraction = extract(image, imageId, tar, fakeContainerFileSystemFile, null, fakeResultsFile, executableRunner);
    assertEquals("ubuntu:latest", extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA).get());
    assertTrue(extraction.getMetaData(DockerExtractor.CONTAINER_FILESYSTEM_META_DATA).get().getName().endsWith("_containerfilesystem.tar.gz"));
    ArgumentCaptor<Executable> executableArgumentCaptor = ArgumentCaptor.forClass(Executable.class);
    Mockito.verify(executableRunner).execute(executableArgumentCaptor.capture());
    Executable executableToVerify = executableArgumentCaptor.getValue();
    List<String> command = executableToVerify.getCommandWithArguments();
    assertTrue(command.get(0).endsWith("/fake/test/java"));
    assertEquals("-jar", command.get(1));
    assertTrue(command.get(2).endsWith("/fake/test/dockerinspector.jar"));
    assertTrue(command.get(3).startsWith("--spring.config.location="));
    assertTrue(command.get(3).endsWith("/application.properties"));
    assertEquals("--docker.image=ubuntu:latest", command.get(4));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Aggregations

DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)17 Test (org.junit.jupiter.api.Test)14 Executable (com.synopsys.integration.executable.Executable)9 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)9 Extraction (com.synopsys.integration.detectable.extraction.Extraction)7 File (java.io.File)7 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)5 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)4 ClangPackageManagerInfoFactory (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory)3 PackageDetails (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)3 ArrayList (java.util.ArrayList)3 Gson (com.google.gson.Gson)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)2 ClangPackageManager (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager)2 ClangPackageManagerRunner (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner)2 DpkgPackageManagerResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver)2 DpkgPkgDetailsResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver)2 GoModCliExtractor (com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2