graph/db: check for wrapped errors

In preparation for a different store impl which may wrap errors, we
use `require.ErrorIs` for error assertions rather than direct "="
comparisons in tests.
This commit is contained in:
Elle Mouton committed 2025-05-22 14:14:41 +02:00
1 parent 227e49d0ae
commit 95220b7102
1 file changed
+7 -15
+7 -15
View File
@@ -167,9 +167,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// Finally, attempt to fetch the node again. This should fail as the // Finally, attempt to fetch the node again. This should fail as the
// node should have been deleted from the database. // node should have been deleted from the database.
_, err = graph.FetchLightningNode(testPub) _, err = graph.FetchLightningNode(testPub)
if err != ErrGraphNodeNotFound { require.ErrorIs(t, err, ErrGraphNodeNotFound)
t.Fatalf("fetch after delete should fail!")
}
} }
// TestPartialNode checks that we can add and retrieve a LightningNode where // TestPartialNode checks that we can add and retrieve a LightningNode where
@@ -273,9 +271,7 @@ func TestAliasLookup(t *testing.T) {
nodePub, err = node.PubKey() nodePub, err = node.PubKey()
require.NoError(t, err, "unable to generate pubkey") require.NoError(t, err, "unable to generate pubkey")
_, err = graph.LookupAlias(nodePub) _, err = graph.LookupAlias(nodePub)
if err != ErrNodeAliasNotFound { require.ErrorIs(t, err, ErrNodeAliasNotFound)
t.Fatalf("alias lookup should fail for non-existent pubkey")
}
} }
func TestSourceNode(t *testing.T) { func TestSourceNode(t *testing.T) {
@@ -290,9 +286,8 @@ func TestSourceNode(t *testing.T) {
// Attempt to fetch the source node, this should return an error as the // Attempt to fetch the source node, this should return an error as the
// source node hasn't yet been set. // source node hasn't yet been set.
if _, err := graph.SourceNode(); err != ErrSourceNodeNotSet { _, err = graph.SourceNode()
t.Fatalf("source node shouldn't be set in new graph") require.ErrorIs(t, err, ErrSourceNodeNotSet)
}
// Set the source the source node, this should insert the node into the // Set the source the source node, this should insert the node into the
// database in a special way indicating it's the source node. // database in a special way indicating it's the source node.
@@ -387,9 +382,7 @@ func TestEdgeInsertionDeletion(t *testing.T) {
// Finally, attempt to delete a (now) non-existent edge within the // Finally, attempt to delete a (now) non-existent edge within the
// database, this should result in an error. // database, this should result in an error.
err = graph.DeleteChannelEdges(false, true, chanID) err = graph.DeleteChannelEdges(false, true, chanID)
if err != ErrEdgeNotFound { require.ErrorIs(t, err, ErrEdgeNotFound)
t.Fatalf("deleting a non-existent edge should fail!")
}
} }
func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32, func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32,
@@ -721,9 +714,8 @@ func TestEdgeInfoUpdates(t *testing.T) {
// Make sure inserting the policy at this point, before the edge info // Make sure inserting the policy at this point, before the edge info
// is added, will fail. // is added, will fail.
if err := graph.UpdateEdgePolicy(edge1); err != ErrEdgeNotFound { err = graph.UpdateEdgePolicy(edge1)
t.Fatalf("expected ErrEdgeNotFound, got: %v", err) require.ErrorIs(t, err, ErrEdgeNotFound)
}
require.Len(t, graph.graphCache.nodeChannels, 0) require.Len(t, graph.graphCache.nodeChannels, 0)
// Add the edge info. // Add the edge info.