multi: move many t.Fatalf calls to require.NoError

This commit is contained in:
Tommy Volk
2022-05-05 20:11:50 +00:00
parent 9e6f0ef46b
commit 9a10c80bcb
92 changed files with 1905 additions and 5565 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/stretchr/testify/require"
)
type moreChansResp struct {
@@ -160,9 +161,7 @@ func setup(t *testing.T, initialChans []LocalChannel) (*testContext, func()) {
// First, we'll create all the dependencies that we'll need in order to
// create the autopilot agent.
self, err := randKey()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
quit := make(chan struct{})
heuristic := &mockHeuristic{
@@ -216,9 +215,7 @@ func setup(t *testing.T, initialChans []LocalChannel) (*testContext, func()) {
}
agent, err := New(testCfg, initialChans)
if err != nil {
t.Fatalf("unable to create agent: %v", err)
}
require.NoError(t, err, "unable to create agent")
ctx.agent = agent
// With the autopilot agent and all its dependencies we'll start the
@@ -331,9 +328,7 @@ func TestAgentHeuristicUpdateSignal(t *testing.T) {
defer cleanup()
pub, err := testCtx.graph.addRandNode()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
// We'll send an initial "no" response to advance the agent past its
// initial check.
@@ -397,9 +392,7 @@ func TestAgentChannelFailureSignal(t *testing.T) {
testCtx.chanController = &mockFailingChanController{}
node, err := testCtx.graph.addRandNode()
if err != nil {
t.Fatalf("unable to add node: %v", err)
}
require.NoError(t, err, "unable to add node")
// First ensure the agent will attempt to open a new channel. Return
// that we need more channels, and have 5BTC to use.
@@ -664,9 +657,7 @@ func TestAgentPendingChannelState(t *testing.T) {
// We'll only return a single directive for a pre-chosen node.
nodeKey, err := testCtx.graph.addRandNode()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
nodeID := NewNodeID(nodeKey)
nodeDirective := &NodeScore{
NodeID: nodeID,
@@ -876,9 +867,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
// We'll only return a single directive for a pre-chosen node.
nodeKey, err := testCtx.graph.addRandNode()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
nodeID := NewNodeID(nodeKey)
nodeDirective := &NodeScore{
NodeID: nodeID,
@@ -888,9 +877,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
// We'll also add a second node to the graph, to keep the first one
// company.
nodeKey2, err := testCtx.graph.addRandNode()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
nodeID2 := NewNodeID(nodeKey2)
// We'll send an initial "yes" response to advance the agent past its
@@ -1062,9 +1049,7 @@ func TestAgentQuitWhenPendingConns(t *testing.T) {
// We'll only return a single directive for a pre-chosen node.
nodeKey, err := testCtx.graph.addRandNode()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
nodeID := NewNodeID(nodeKey)
nodeDirective := &NodeScore{
NodeID: nodeID,

View File

@@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/stretchr/testify/require"
)
type genGraphFunc func() (testGraph, func(), error)
@@ -77,9 +78,7 @@ func TestPrefAttachmentSelectEmptyGraph(t *testing.T) {
// Create a random public key, which we will query to get a score for.
pub, err := randKey()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
nodes := map[NodeID]struct{}{
NewNodeID(pub): {},