Search in sources :

Example 1 with ReplaceData

use of com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData in project synopsys-detect by blackducksoftware.

the class GoListParserTest method goListAllHappyPathTest.

@Test
void goListAllHappyPathTest() throws DetectableException {
    List<String> goListAllOutput = Arrays.asList("{\n", "\t\"Path\": \"github.com/synopsys/moduleA\",\n", "\t\"Version\": \"v1.0.0\"\n", "}\n", "{\n", "\t\"Path\": \"github.com/synopsys/moduleB\",\n", "\t\"Version\": \"v2.0.0\",\n", "\t\"Replace\": {\n", "\t\t\"Path\": \"github.com/synopsys/moduleB\",\n", "\t\t\"Version\": \"v3.0.0\"\n", "\t}\n", "}");
    List<GoListAllData> goListModules = goListParser.parseGoListAllJsonOutput(goListAllOutput);
    assertEquals(2, goListModules.size());
    GoListAllData moduleA = goListModules.get(0);
    assertEquals("github.com/synopsys/moduleA", moduleA.getPath());
    assertEquals("v1.0.0", moduleA.getVersion());
    assertNull(moduleA.getReplace());
    GoListAllData moduleB = goListModules.get(1);
    assertEquals("github.com/synopsys/moduleB", moduleB.getPath());
    assertEquals("v2.0.0", moduleB.getVersion());
    ReplaceData replaceData = moduleB.getReplace();
    assertEquals("github.com/synopsys/moduleB", replaceData.getPath());
    assertEquals("v3.0.0", replaceData.getVersion());
}
Also used : ReplaceData(com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) Test(org.junit.jupiter.api.Test)

Example 2 with ReplaceData

use of com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData in project synopsys-detect by blackducksoftware.

the class GoModDependencyManagerTest method moduleReplacementTest.

@Test
void moduleReplacementTest() {
    String resolvedModulePath = "example.io/module/resolved";
    String replacedModulePath = "example.io/module/replaced";
    GoListAllData resolvedModule = new GoListAllData();
    resolvedModule.setPath(resolvedModulePath);
    resolvedModule.setVersion("1.0.0");
    GoListAllData replacedModule = new GoListAllData();
    replacedModule.setPath(replacedModulePath);
    replacedModule.setVersion("2.0.0");
    ReplaceData replaceData = new ReplaceData();
    replaceData.setPath(resolvedModulePath);
    replaceData.setVersion("2.3.4");
    replacedModule.setReplace(replaceData);
    GoModDependencyManager dependencyManager = new GoModDependencyManager(Arrays.asList(resolvedModule, replacedModule), new ExternalIdFactory());
    Dependency resolvedDependency = dependencyManager.getDependencyForModule(resolvedModule.getPath());
    assertEquals(resolvedModule.getPath(), resolvedDependency.getName());
    assertEquals(resolvedModule.getVersion(), resolvedDependency.getVersion());
    Dependency replacedDependency = dependencyManager.getDependencyForModule(replacedModulePath);
    assertEquals(replaceData.getPath(), replacedDependency.getName(), "The dependency name (module path) should have been replaced.");
    assertEquals(replaceData.getVersion(), replacedDependency.getVersion(), "The version should have been replaced.");
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ReplaceData(com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) Test(org.junit.jupiter.api.Test)

Aggregations

GoListAllData (com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)2 ReplaceData (com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData)2 Test (org.junit.jupiter.api.Test)2 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1