|
| 1 | +package com.blackduck.integration.detectable.detectables.conda.functional; |
| 2 | + |
| 3 | +import com.blackduck.integration.bdio.model.Forge; |
| 4 | +import com.blackduck.integration.detectable.Detectable; |
| 5 | +import com.blackduck.integration.detectable.DetectableEnvironment; |
| 6 | +import com.blackduck.integration.detectable.ExecutableTarget; |
| 7 | +import com.blackduck.integration.detectable.detectable.exception.DetectableException; |
| 8 | +import com.blackduck.integration.detectable.detectable.executable.resolver.CondaResolver; |
| 9 | +import com.blackduck.integration.detectable.detectables.conda.CondaCliDetectableOptions; |
| 10 | +import com.blackduck.integration.detectable.extraction.Extraction; |
| 11 | +import com.blackduck.integration.detectable.functional.DetectableFunctionalTest; |
| 12 | +import com.blackduck.integration.detectable.util.graph.NameVersionGraphAssert; |
| 13 | +import com.blackduck.integration.executable.ExecutableOutput; |
| 14 | +import org.jetbrains.annotations.NotNull; |
| 15 | +import org.junit.jupiter.api.Assertions; |
| 16 | + |
| 17 | +import java.io.IOException; |
| 18 | + |
| 19 | +public class CondaDetectableTest extends DetectableFunctionalTest { |
| 20 | + |
| 21 | + public CondaDetectableTest() throws IOException { |
| 22 | + super("conda"); |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + protected void setup() throws IOException { |
| 27 | + addFile("environment.yaml"); |
| 28 | + |
| 29 | + ExecutableOutput condaListOutput = createStandardOutput( |
| 30 | + "[", |
| 31 | + " {", |
| 32 | + " \"base_url\": null,", |
| 33 | + " \"build_number\": 0,", |
| 34 | + " \"build_string\": \"0\",", |
| 35 | + " \"channel\": \"defaults\",", |
| 36 | + " \"dist_name\": \"mkl-2017.0.3-0\",", |
| 37 | + " \"name\": \"mkl\",", |
| 38 | + " \"platform\": null,", |
| 39 | + " \"version\": \"2017.0.3\",", |
| 40 | + " \"with_features_depends\": null", |
| 41 | + " }", |
| 42 | + "]" |
| 43 | + ); |
| 44 | + addExecutableOutput(condaListOutput, "conda", "list", "-n", "conda-env", "--json"); |
| 45 | + |
| 46 | + ExecutableOutput condaInfoOutput = createStandardOutput( |
| 47 | + "{", |
| 48 | + " \"conda_build_version\": \"not installed\",", |
| 49 | + " \"conda_env_version\": \"4.3.22\",", |
| 50 | + " \"conda_location\": \"/usr/local/miniconda3/lib/python3.6/site-packages/conda\",", |
| 51 | + " \"conda_prefix\": \"/usr/local/miniconda3\",", |
| 52 | + " \"conda_private\": false,", |
| 53 | + " \"conda_version\": \"4.3.22\",", |
| 54 | + " \"default_prefix\": \"/usr/local/miniconda3\",", |
| 55 | + " \"platform\": \"win-64\"", |
| 56 | + "}" |
| 57 | + ); |
| 58 | + addExecutableOutput(getOutputDirectory(), condaInfoOutput, "conda", "info", "--json"); |
| 59 | + } |
| 60 | + |
| 61 | + @NotNull |
| 62 | + @Override |
| 63 | + public Detectable create(@NotNull DetectableEnvironment detectableEnvironment) { |
| 64 | + class CondaResolverTest implements CondaResolver { |
| 65 | + |
| 66 | + @Override |
| 67 | + public ExecutableTarget resolveConda() throws DetectableException { |
| 68 | + return ExecutableTarget.forCommand("conda"); |
| 69 | + } |
| 70 | + } |
| 71 | + return detectableFactory.createCondaCliDetectable(detectableEnvironment, new CondaResolverTest(), new CondaCliDetectableOptions("conda-env")); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public void assertExtraction(@NotNull Extraction extraction) { |
| 76 | + Assertions.assertEquals(1, extraction.getCodeLocations().size()); |
| 77 | + |
| 78 | + NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.ANACONDA, extraction.getCodeLocations().get(0).getDependencyGraph()); |
| 79 | + graphAssert.hasRootSize(1); |
| 80 | + graphAssert.hasRootDependency("mkl", "2017.0.3-0-win-64"); |
| 81 | + |
| 82 | + } |
| 83 | +} |
0 commit comments