Skip to content

Commit

Permalink
Merge pull request #706 from weaveworks/656-unconnected
Browse files Browse the repository at this point in the history
Filter nodes that are only connected to themselves.
  • Loading branch information
tomwilkie committed Dec 1, 2015
2 parents 5632cd8 + 5a1cc3f commit 00e63e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func (c CustomRenderer) Render(rpt report.Report) RenderableNodes {
}

// ColorConnected colors nodes with the IsConnected key if
// they have edges to or from them.
// they have edges to or from them. Edges to/from yourself
// are not counted here (see #656).
func ColorConnected(r Renderer) Renderer {
return CustomRenderer{
Renderer: r,
Expand All @@ -35,9 +36,11 @@ func ColorConnected(r Renderer) Renderer {
continue
}

connected[id] = void
for _, id := range node.Adjacency {
connected[id] = void
for _, adj := range node.Adjacency {
if adj != id {
connected[id] = void
connected[adj] = void
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions render/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,18 @@ func TestFilterUnconnectedPesudoNodes(t *testing.T) {
}
}
}

func TestFilterUnconnectedSelf(t *testing.T) {
// Test nodes that are only connected to themselves are filtered.
{
nodes := render.RenderableNodes{
"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("foo")},
}
renderer := render.FilterUnconnected(mockRenderer{RenderableNodes: nodes})
want := render.RenderableNodes{}
have := renderer.Render(report.MakeReport()).Prune()
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}

0 comments on commit 00e63e8

Please sign in to comment.