Skip to content

Commit 01ed6f2

Browse files
committed
graph/db: add TestVersionedDBs
This will be used to run sub-tests with v2 data.
1 parent 6f1ddae commit 01ed6f2

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

graph/db/graph_test.go

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,47 @@ func createTestVertex(t testing.TB, v lnwire.GossipVersion) *models.Node {
120120
return createNode(t, v, priv)
121121
}
122122

123-
// TestNodeInsertionAndDeletion tests the CRUD operations for a Node.
124-
func TestNodeInsertionAndDeletion(t *testing.T) {
123+
type versionedTest struct {
124+
name string
125+
test func(t *testing.T, v lnwire.GossipVersion)
126+
}
127+
128+
var versionedTests = []versionedTest{
129+
{
130+
name: "node crud",
131+
test: testNodeInsertionAndDeletion,
132+
},
133+
}
134+
135+
// TestVersionedDBs runs various tests against both v1 and v2 versioned
136+
// backends.
137+
func TestVersionedDBs(t *testing.T) {
125138
t.Parallel()
126-
ctx := t.Context()
127139

128-
graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1)
140+
for _, vt := range versionedTests {
141+
vt := vt
142+
143+
t.Run(vt.name+"/v1", func(t *testing.T) {
144+
vt.test(t, lnwire.GossipVersion1)
145+
})
146+
147+
if !isSQLDB {
148+
continue
149+
}
150+
151+
t.Run(vt.name+"/v2", func(t *testing.T) {
152+
vt.test(t, lnwire.GossipVersion2)
153+
})
154+
}
155+
}
129156

130-
// We'd like to test basic insertion/deletion for vertexes from the
131-
// graph, so we'll create a test vertex to start with.
132-
timeStamp := int64(1232342)
157+
// testNodeInsertionAndDeletion tests the CRUD operations for a Node.
158+
func testNodeInsertionAndDeletion(t *testing.T, v lnwire.GossipVersion) {
133159
nodeWithAddrs := func(addrs []net.Addr) *models.Node {
134-
timeStamp++
135160
return models.NewV1Node(
136161
testPub, &models.NodeV1Fields{
137162
AuthSigBytes: testSig.Serialize(),
138-
LastUpdate: time.Unix(timeStamp, 0),
163+
LastUpdate: nextUpdateTime(),
139164
Color: color.RGBA{1, 2, 3, 0},
140165
Alias: "kek",
141166
Features: testFeatures.RawFeatureVector,
@@ -145,6 +170,31 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
145170
)
146171
}
147172

173+
if v == lnwire.GossipVersion2 {
174+
nodeWithAddrs = func(addrs []net.Addr) *models.Node {
175+
return models.NewV2Node(
176+
testPub, &models.NodeV2Fields{
177+
Signature: testSig.Serialize(),
178+
LastBlockHeight: nextBlockHeight(),
179+
Color: fn.Some(
180+
color.RGBA{1, 2, 3, 0},
181+
),
182+
Alias: fn.Some("kek"),
183+
Features: testFeatures.
184+
RawFeatureVector,
185+
Addresses: addrs,
186+
ExtraSignedFields: map[uint64][]byte{
187+
20: {0x1, 0x2, 0x3},
188+
21: {0x4, 0x5, 0x6, 0x7},
189+
},
190+
},
191+
)
192+
}
193+
}
194+
195+
ctx := t.Context()
196+
graph := NewVersionedGraph(MakeTestGraph(t), v)
197+
148198
// First, insert the node into the graph DB. This should succeed
149199
// without any errors.
150200
node := nodeWithAddrs(testAddrs)

0 commit comments

Comments
 (0)