github.com/decred/dcrlnd@v0.7.6/routing/dcrlnd_router_test.go (about)

     1  package routing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/decred/dcrlnd/channeldb"
     7  	"github.com/decred/dcrlnd/kvdb"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  // TestForAllOutgoingFiltersNonOpen asserts the function only iterates over
    12  // opened channels.
    13  func TestForAllOutgoingFiltersNonOpen(t *testing.T) {
    14  	const startingBlockHeight = 100
    15  	ctx, cleanUp := createTestCtxFromFile(
    16  		t, startingBlockHeight, basicGraphFilePath,
    17  	)
    18  	defer cleanUp()
    19  
    20  	// Configure one channel as being opened. The others will be closed.
    21  	ctx.router.cfg.LocalOpenChanIDs = func() (map[uint64]struct{}, error) {
    22  		return map[uint64]struct{}{999991: {}}, nil
    23  	}
    24  
    25  	// Only a single channel should be returned by this function.
    26  	var nbChans int
    27  	err := ctx.router.ForAllOutgoingChannels(func(kvdb.RTx,
    28  		*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy) error {
    29  		nbChans += 1
    30  		return nil
    31  	})
    32  	require.NoError(t, err)
    33  	require.Equal(t, 1, nbChans)
    34  }