@@ -50,55 +50,70 @@ func TestCombinedIterator(t *testing.T) {
50
50
// prepare batch2 (empty)
51
51
batch2 := statedb .NewUpdateBatch ()
52
52
53
- // Test db + batch1 updates
53
+ // Test db + batch1 updates (exclude endKey)
54
54
itr1 , _ := newCombinedIterator (db , batch1 , "ns" , "key2" , "key8" , false )
55
55
defer itr1 .Close ()
56
- checkItrResults (t , itr1 , []* statedb.VersionedKV {
56
+ checkItrResults (t , "ExcludeEndKey" , itr1 , []* statedb.VersionedKV {
57
57
constructVersionedKV ("ns" , "key3" , []byte ("value3" ), version .NewHeight (1 , 1 )),
58
58
constructVersionedKV ("ns" , "key4" , []byte ("value4" ), version .NewHeight (1 , 1 )),
59
59
constructVersionedKV ("ns" , "key6" , []byte ("value6_new" ), version .NewHeight (1 , 1 )),
60
60
constructVersionedKV ("ns" , "key7" , []byte ("value7" ), version .NewHeight (1 , 1 )),
61
61
})
62
62
63
+ // Test db + batch1 updates (include endKey)
63
64
itr1WithEndKey , _ := newCombinedIterator (db , batch1 , "ns" , "key2" , "key8" , true )
64
65
defer itr1WithEndKey .Close ()
65
- checkItrResults (t , itr1WithEndKey , []* statedb.VersionedKV {
66
+ checkItrResults (t , "IncludeEndKey" , itr1WithEndKey , []* statedb.VersionedKV {
66
67
constructVersionedKV ("ns" , "key3" , []byte ("value3" ), version .NewHeight (1 , 1 )),
67
68
constructVersionedKV ("ns" , "key4" , []byte ("value4" ), version .NewHeight (1 , 1 )),
68
69
constructVersionedKV ("ns" , "key6" , []byte ("value6_new" ), version .NewHeight (1 , 1 )),
69
70
constructVersionedKV ("ns" , "key7" , []byte ("value7" ), version .NewHeight (1 , 1 )),
70
71
constructVersionedKV ("ns" , "key8" , []byte ("value8" ), version .NewHeight (1 , 1 )),
71
72
})
72
73
73
- // Test db + batch2 updates
74
- itr2 , _ := newCombinedIterator (db , batch2 , "ns" , "key2" , "key8" , false )
75
- defer itr2 .Close ()
76
- checkItrResults (t , itr2 , []* statedb.VersionedKV {
74
+ // Test db + batch1 updates (include endKey) for extra range
75
+ itr1WithEndKeyExtraRange , _ := newCombinedIterator (db , batch1 , "ns" , "key0" , "key9" , true )
76
+ defer itr1WithEndKeyExtraRange .Close ()
77
+ checkItrResults (t , "IncludeEndKey_ExtraRange" , itr1WithEndKeyExtraRange , []* statedb.VersionedKV {
78
+ constructVersionedKV ("ns" , "key1" , []byte ("value1" ), version .NewHeight (1 , 1 )),
79
+ constructVersionedKV ("ns" , "key3" , []byte ("value3" ), version .NewHeight (1 , 1 )),
77
80
constructVersionedKV ("ns" , "key4" , []byte ("value4" ), version .NewHeight (1 , 1 )),
78
- constructVersionedKV ("ns" , "key6" , []byte ("value6" ), version .NewHeight (1 , 1 )),
81
+ constructVersionedKV ("ns" , "key6" , []byte ("value6_new" ), version .NewHeight (1 , 1 )),
82
+ constructVersionedKV ("ns" , "key7" , []byte ("value7" ), version .NewHeight (1 , 1 )),
83
+ constructVersionedKV ("ns" , "key8" , []byte ("value8" ), version .NewHeight (1 , 1 )),
79
84
})
80
85
81
86
// Test db + batch1 updates with full range query
82
87
itr3 , _ := newCombinedIterator (db , batch1 , "ns" , "" , "" , false )
83
88
defer itr3 .Close ()
84
- checkItrResults (t , itr3 , []* statedb.VersionedKV {
89
+ checkItrResults (t , "ExcludeEndKey_FullRange" , itr3 , []* statedb.VersionedKV {
85
90
constructVersionedKV ("ns" , "key1" , []byte ("value1" ), version .NewHeight (1 , 1 )),
86
91
constructVersionedKV ("ns" , "key3" , []byte ("value3" ), version .NewHeight (1 , 1 )),
87
92
constructVersionedKV ("ns" , "key4" , []byte ("value4" ), version .NewHeight (1 , 1 )),
88
93
constructVersionedKV ("ns" , "key6" , []byte ("value6_new" ), version .NewHeight (1 , 1 )),
89
94
constructVersionedKV ("ns" , "key7" , []byte ("value7" ), version .NewHeight (1 , 1 )),
90
95
constructVersionedKV ("ns" , "key8" , []byte ("value8" ), version .NewHeight (1 , 1 )),
91
96
})
97
+
98
+ // Test db + batch2 updates
99
+ itr2 , _ := newCombinedIterator (db , batch2 , "ns" , "key2" , "key8" , false )
100
+ defer itr2 .Close ()
101
+ checkItrResults (t , "ExcludeEndKey_EmptyUpdates" , itr2 , []* statedb.VersionedKV {
102
+ constructVersionedKV ("ns" , "key4" , []byte ("value4" ), version .NewHeight (1 , 1 )),
103
+ constructVersionedKV ("ns" , "key6" , []byte ("value6" ), version .NewHeight (1 , 1 )),
104
+ })
92
105
}
93
106
94
- func checkItrResults (t * testing.T , itr statedb.ResultsIterator , expectedResults []* statedb.VersionedKV ) {
95
- for i := 0 ; i < len (expectedResults ); i ++ {
96
- res , _ := itr .Next ()
97
- testutil .AssertEquals (t , res , expectedResults [i ])
98
- }
99
- lastRes , err := itr .Next ()
100
- testutil .AssertNoError (t , err , "" )
101
- testutil .AssertNil (t , lastRes )
107
+ func checkItrResults (t * testing.T , testName string , itr statedb.ResultsIterator , expectedResults []* statedb.VersionedKV ) {
108
+ t .Run (testName , func (t * testing.T ) {
109
+ for i := 0 ; i < len (expectedResults ); i ++ {
110
+ res , _ := itr .Next ()
111
+ testutil .AssertEquals (t , res , expectedResults [i ])
112
+ }
113
+ lastRes , err := itr .Next ()
114
+ testutil .AssertNoError (t , err , "" )
115
+ testutil .AssertNil (t , lastRes )
116
+ })
102
117
}
103
118
104
119
func constructVersionedKV (ns string , key string , value []byte , version * version.Height ) * statedb.VersionedKV {
0 commit comments