graph/db: add NewTestDB method

In this commit, we add a `test_kvdb.go` file with a single definition of
the `NewTestDB` function. A new version of `MakeTestGraph` (called
`MakeTestGraphNew` is added which makes use of this `NewTestDB` function
to create the backing `V1Store` passed to the `ChannelGraph` for tests.

Later on, we will add new implementations of this method backed by
sqlite and postgres.  When those are added, then build flags will
control which version of `NewTestDB` is called.

With this change, the only test call-site of `NewKVStore` is the new
`test_kvdb.go` file.
This commit is contained in:
Elle Mouton committed 2025-05-22 14:14:42 +02:00
1 parent dc353dc50e
commit b285546ce1
4 files changed
+55 -10

No files matched your search

+2 -10
View File
@@ -4128,18 +4128,10 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) {
// TestGraphLoading asserts that the cache is properly reconstructed after a
// restart.
func TestGraphLoading(t *testing.T) {
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName := t.TempDir()
t.Parallel()
// Next, create the graph for the first time.
backend, backendCleanup, err := kvdb.GetTestBackend(tempDirName, "cgr")
require.NoError(t, err)
defer backend.Close()
defer backendCleanup()
graphStore, err := NewKVStore(backend)
require.NoError(t, err)
graphStore := NewTestDB(t)
graph, err := NewChannelGraph(graphStore)
require.NoError(t, err)