Addressed the comments and fixed the tests.

This commit is contained in:
Filip Barl
2017-02-17 14:21:53 +01:00
parent f1904a626f
commit 2e9255b190
15 changed files with 200 additions and 150 deletions

30
test/utils/prune.go Normal file
View File

@@ -0,0 +1,30 @@
package utils
import (
"github.com/weaveworks/scope/report"
)
// Prune returns a copy of the Nodes with all information not strictly
// necessary for rendering nodes and edges in the UI cut away.
func Prune(nodes report.Nodes) report.Nodes {
result := report.Nodes{}
for id, node := range nodes {
result[id] = PruneNode(node)
}
return result
}
// PruneNode returns a copy of the Node with all information not strictly
// necessary for rendering nodes and edges stripped away. Specifically, that
// means cutting out parts of the Node.
func PruneNode(node report.Node) report.Node {
prunedChildren := report.MakeNodeSet()
node.Children.ForEach(func(child report.Node) {
prunedChildren = prunedChildren.Add(PruneNode(child))
})
return report.MakeNode(
node.ID).
WithTopology(node.Topology).
WithAdjacent(node.Adjacency.Copy()...).
WithChildren(prunedChildren)
}