graph/db: refactor TestNodeIsPublic to use require assertions

Replace verbose t.Fatal patterns with concise require assertions
following the project's testing guidelines.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:22 +02:00
1 parent fa24d336c1
commit 86732fae99
1 file changed
+12 -30
+12 -30
View File
@@ -4079,21 +4079,18 @@ func TestNodeIsPublic(t *testing.T) {
// some graphs but not others, etc.). // some graphs but not others, etc.).
aliceGraph := MakeTestGraph(t) aliceGraph := MakeTestGraph(t)
aliceNode := createTestVertex(t, lnwire.GossipVersion1) aliceNode := createTestVertex(t, lnwire.GossipVersion1)
if err := aliceGraph.SetSourceNode(ctx, aliceNode); err != nil { err := aliceGraph.SetSourceNode(ctx, aliceNode)
t.Fatalf("unable to set source node: %v", err) require.NoError(t, err, "unable to set source node")
}
bobGraph := MakeTestGraph(t) bobGraph := MakeTestGraph(t)
bobNode := createTestVertex(t, lnwire.GossipVersion1) bobNode := createTestVertex(t, lnwire.GossipVersion1)
if err := bobGraph.SetSourceNode(ctx, bobNode); err != nil { err = bobGraph.SetSourceNode(ctx, bobNode)
t.Fatalf("unable to set source node: %v", err) require.NoError(t, err, "unable to set source node")
}
carolGraph := MakeTestGraph(t) carolGraph := MakeTestGraph(t)
carolNode := createTestVertex(t, lnwire.GossipVersion1) carolNode := createTestVertex(t, lnwire.GossipVersion1)
if err := carolGraph.SetSourceNode(ctx, carolNode); err != nil { err = carolGraph.SetSourceNode(ctx, carolNode)
t.Fatalf("unable to set source node: %v", err) require.NoError(t, err, "unable to set source node")
}
aliceBobEdge, _ := createEdge(10, 0, 0, 0, aliceNode, bobNode) aliceBobEdge, _ := createEdge(10, 0, 0, 0, aliceNode, bobNode)
bobCarolEdge, _ := createEdge(10, 1, 0, 1, bobNode, carolNode) bobCarolEdge, _ := createEdge(10, 1, 0, 1, bobNode, carolNode)
@@ -4127,19 +4124,9 @@ func TestNodeIsPublic(t *testing.T) {
isPublic, err := graph.IsPublicNode( isPublic, err := graph.IsPublicNode(
node.PubKeyBytes, node.PubKeyBytes,
) )
if err != nil { require.NoError(t, err)
t.Fatalf("unable to determine if "+
"pivot is public: %v", err)
}
switch { require.Equal(t, public, isPublic)
case isPublic && !public:
t.Fatalf("expected %x to be private",
node.PubKeyBytes)
case !isPublic && public:
t.Fatalf("expected %x to be public",
node.PubKeyBytes)
}
} }
} }
} }
@@ -4155,9 +4142,7 @@ func TestNodeIsPublic(t *testing.T) {
err := graph.DeleteChannelEdges( err := graph.DeleteChannelEdges(
false, true, aliceBobEdge.ChannelID, false, true, aliceBobEdge.ChannelID,
) )
if err != nil { require.NoError(t, err, "unable to remove edge")
t.Fatalf("unable to remove edge: %v", err)
}
} }
checkNodes( checkNodes(
[]*models.Node{aliceNode}, []*models.Node{aliceNode},
@@ -4174,18 +4159,15 @@ func TestNodeIsPublic(t *testing.T) {
err := graph.DeleteChannelEdges( err := graph.DeleteChannelEdges(
false, true, bobCarolEdge.ChannelID, false, true, bobCarolEdge.ChannelID,
) )
if err != nil { require.NoError(t, err, "unable to remove edge")
t.Fatalf("unable to remove edge: %v", err)
}
if graph == aliceGraph { if graph == aliceGraph {
continue continue
} }
bobCarolEdge.AuthProof = nil bobCarolEdge.AuthProof = nil
if err := graph.AddChannelEdge(ctx, bobCarolEdge); err != nil { err = graph.AddChannelEdge(ctx, bobCarolEdge)
t.Fatalf("unable to add edge: %v", err) require.NoError(t, err, "unable to add edge")
}
} }
// With the modifications above, Bob should now be seen as a private // With the modifications above, Bob should now be seen as a private