From d97e7d30fb9af989cd83ca87a63d55a2088694aa Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sun, 19 Nov 2023 11:09:21 +0100 Subject: [PATCH] channeldb/test: refactor TestGraphCacheForEachNodeChannel --- channeldb/graph_test.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index 8fe90c545..5c2b0c324 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -3934,19 +3934,24 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) { // Add the channel, but only insert a single edge into the graph. require.NoError(t, graph.AddChannelEdge(edgeInfo)) + getSingleChannel := func() *DirectedChannel { + var ch *DirectedChannel + err = graph.ForEachNodeDirectedChannel(nil, node1.PubKeyBytes, + func(c *DirectedChannel) error { + require.Nil(t, ch) + ch = c + + return nil + }, + ) + require.NoError(t, err) + + return ch + } + // We should be able to accumulate the single channel added, even // though we have a nil edge policy here. - var numChans int - err = graph.ForEachNodeDirectedChannel(nil, node1.PubKeyBytes, - func(_ *DirectedChannel) error { - numChans++ - - return nil - }, - ) - require.NoError(t, err) - - require.Equal(t, numChans, 1) + require.NotNil(t, getSingleChannel()) } // TestGraphLoading asserts that the cache is properly reconstructed after a