From 5a1cc3fa8fb701b13009c9fd2d9c35295a061d8c Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 30 Nov 2015 12:43:02 +0000 Subject: [PATCH] Filter nodes that are only connected to themselves. --- render/filters.go | 11 +++++++---- render/filters_test.go | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/render/filters.go b/render/filters.go index 84711d1771..9bacd0c3dc 100644 --- a/render/filters.go +++ b/render/filters.go @@ -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, @@ -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 + } } } diff --git a/render/filters_test.go b/render/filters_test.go index 905fea177f..325e29d25d 100644 --- a/render/filters_test.go +++ b/render/filters_test.go @@ -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)) + } + } +}