-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow skip VCS stamping in Go (#689)
- Loading branch information
Showing
5 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...tractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoDependencyTreeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.jfrog.build.extractor.go.extractor; | ||
|
||
import com.google.common.collect.Sets; | ||
import org.jfrog.build.api.util.NullLog; | ||
import org.jfrog.build.extractor.scan.DependencyTree; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.*; | ||
|
||
import static org.jfrog.build.extractor.go.extractor.GoDependencyTree.populateDependenciesMap; | ||
import static org.jfrog.build.extractor.go.extractor.GoDependencyTree.populateDependencyTree; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
/** | ||
* @author yahavi | ||
**/ | ||
public class GoDependencyTreeTest { | ||
|
||
@Test | ||
public void testPopulateDependenciesMap() { | ||
// Output of 'go mod graph'. | ||
String[] dependenciesGraph = new String[]{ | ||
"my/pkg/name1 github.com/jfrog/[email protected]", | ||
"my/pkg/name1 github.com/jfrog/[email protected]", | ||
"my/pkg/name1 github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected] github.com/jfrog/[email protected]", | ||
// github.com/jfrog/[email protected] does not appear in the used modules set: | ||
"github.com/jfrog/[email protected] github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected] github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected] github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected] github.com/jfrog/[email protected]" | ||
}; | ||
Set<String> usedModules = Sets.newHashSet("github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]"); | ||
// Run method. | ||
Map<String, List<String>> expectedAllDependencies = getAllDependenciesForTest(); | ||
Map<String, List<String>> actualAllDependencies = new HashMap<>(); | ||
populateDependenciesMap(dependenciesGraph, usedModules, actualAllDependencies); | ||
// Validate result. | ||
assertEquals(expectedAllDependencies, actualAllDependencies); | ||
} | ||
|
||
@Test | ||
public void testPopulateDependencyTree() { | ||
Map<String, Integer> expected = new HashMap<String, Integer>() {{ | ||
put("github.com/jfrog/directDep1:0.1", 2); | ||
put("github.com/jfrog/directDep2:0.2", 1); | ||
put("github.com/jfrog/directDep3:0.3", 0); | ||
}}; | ||
Map<String, List<String>> allDependencies = getAllDependenciesForTest(); | ||
DependencyTree rootNode = new DependencyTree(); | ||
populateDependencyTree(rootNode, "my/pkg/name1", allDependencies, new NullLog()); | ||
|
||
Vector<DependencyTree> children = rootNode.getChildren(); | ||
assertEquals(children.size(), expected.size()); | ||
for (DependencyTree current : children) { | ||
assertTrue(expected.containsKey(current.toString())); | ||
assertEquals(current.getChildren().size(), expected.get(current.toString()).intValue()); | ||
} | ||
} | ||
|
||
private Map<String, List<String>> getAllDependenciesForTest() { | ||
return new HashMap<String, List<String>>() {{ | ||
put("my/pkg/name1", Arrays.asList( | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]")); | ||
put("github.com/jfrog/[email protected]", List.of( | ||
"github.com/jfrog/[email protected]", | ||
"github.com/jfrog/[email protected]")); | ||
put("github.com/jfrog/[email protected]", Collections.singletonList( | ||
"github.com/jfrog/[email protected]")); | ||
put("github.com/jfrog/[email protected]", Collections.singletonList( | ||
"github.com/jfrog/[email protected]")); | ||
}}; | ||
} | ||
} |