@@ -53,128 +53,184 @@ async function validate (store) {
53
53
if ( store instanceof BaseBlockstore ) {
54
54
const key = CID . parse ( `b${ name . toLowerCase ( ) } ` )
55
55
56
- expect ( await store . has ( key ) ) . to . be . true ( `Could not read key ${ name } ` )
57
- expect ( equals ( await store . get ( key ) , keys [ name ] ) ) . to . be . true ( `Could not read value for key ${ keys [ name ] } ` )
56
+ await expect ( store . has ( key ) ) . to . eventually . be . true ( `Could not read key ${ name } from blockstore ` )
57
+ expect ( equals ( await store . get ( key ) , keys [ name ] ) ) . to . be . true ( `Could not read value for key ${ keys [ name ] } from blockstore ` )
58
58
} else {
59
59
const key = new Key ( `/${ name } ` )
60
60
61
- await expect ( store . has ( key ) ) . to . eventually . be . true ( `Could not read key ${ name } ` )
62
- expect ( equals ( await store . get ( key ) , keys [ name ] ) ) . to . be . true ( `Could not read value for key ${ keys [ name ] } ` )
61
+ await expect ( store . has ( key ) ) . to . eventually . be . true ( `Could not read key ${ name } from datastore ` )
62
+ expect ( equals ( await store . get ( key ) , keys [ name ] ) ) . to . be . true ( `Could not read value for key ${ keys [ name ] } from datastore ` )
63
63
}
64
64
}
65
65
66
66
await store . close ( )
67
67
}
68
68
69
- /**
70
- * @param {Backends } backends
71
- * @param {* } LevelImpl
72
- * @returns {Backends }
73
- */
74
- function withLevels ( backends , LevelImpl ) {
75
- const output = {
76
- ...backends
77
- }
78
-
79
- Object . entries ( backends )
80
- . forEach ( ( [ key , value ] ) => {
81
- // @ts -ignore it's ok
82
- output [ key ] = withLevel ( value , LevelImpl )
83
- } )
84
-
85
- return output
86
- }
87
-
88
- /**
89
- * @param {Datastore } store
90
- * @param {* } LevelImpl
91
- */
92
- function withLevel ( store , LevelImpl ) {
93
- let parent = {
94
- child : store
95
- }
96
-
97
- while ( parent . child ) {
98
- if ( parent . child . constructor . name === 'LevelDatastore' ) {
99
- // @ts -ignore undocumented properties
100
- parent . child . database = LevelImpl
101
- // @ts -ignore undocumented properties
102
- delete parent . child . db
103
-
104
- return store
105
- }
106
-
107
- // @ts -ignore undocumented properties
108
- parent = parent . child
109
- }
110
-
111
- return store
112
- }
113
-
114
69
/**
115
70
* @param {import('../types').SetupFunction } setup
116
71
* @param {import('../types').CleanupFunction } cleanup
117
72
*/
118
73
export function test ( setup , cleanup ) {
119
74
describe ( 'migration 10' , function ( ) {
120
75
this . timeout ( 1024 * 1000 )
121
- /** @type {string } */
122
- let dir
123
- /** @type {import('../../src/types').Backends } */
124
- let backends
125
-
126
- beforeEach ( async ( ) => {
127
- ( { dir, backends } = await setup ( ) )
128
- } )
129
-
130
- afterEach ( async ( ) => {
131
- await cleanup ( dir )
132
- } )
133
76
134
77
describe ( 'forwards' , ( ) => {
78
+ /** @type {string } */
79
+ let dir
80
+ /** @type {import('../../src/types').Backends } */
81
+ let backends
82
+ /** @type {string } */
83
+ let prefix
84
+
135
85
beforeEach ( async ( ) => {
86
+ ( { dir, prefix, backends } = await setup ( {
87
+ createBackends : {
88
+ createLevel : ( path ) => new Level5 ( path , {
89
+ valueEncoding : 'binary'
90
+ } )
91
+ }
92
+ } ) )
93
+
136
94
for ( const backend of Object . values ( backends ) ) {
137
- await bootstrap ( withLevel ( backend , Level5 ) )
95
+ await bootstrap ( backend )
96
+ }
97
+ } )
98
+
99
+ afterEach ( async ( ) => {
100
+ if ( dir != null ) {
101
+ await cleanup ( dir )
138
102
}
139
103
} )
140
104
141
105
it ( 'should migrate keys and values forward' , async ( ) => {
142
- await migration . migrate ( withLevels ( backends , Level6 ) , ( ) => { } )
106
+ ( { backends } = await setup ( {
107
+ dir,
108
+ prefix,
109
+ createBackends : {
110
+ createLevel : ( path ) => new Level6 ( path , {
111
+ valueEncoding : 'binary'
112
+ } )
113
+ }
114
+ } ) )
115
+
116
+ await migration . migrate ( backends , ( ) => { } )
143
117
144
118
for ( const backend of Object . values ( backends ) ) {
145
- await validate ( withLevel ( backend , Level6 ) )
119
+ await validate ( backend )
146
120
}
147
121
} )
148
122
} )
149
123
150
124
describe ( 'backwards using [email protected] ' , ( ) => {
125
+ /** @type {string } */
126
+ let dir
127
+ /** @type {import('../../src/types').Backends } */
128
+ let backends
129
+ /** @type {string } */
130
+ let prefix
131
+
151
132
beforeEach ( async ( ) => {
133
+ ( { dir, prefix, backends } = await setup ( {
134
+ createBackends : {
135
+ createLevel : ( path ) => new Level6 ( path , {
136
+ valueEncoding : 'binary'
137
+ } )
138
+ }
139
+ } ) )
140
+
152
141
for ( const backend of Object . values ( backends ) ) {
153
- await bootstrap ( withLevel ( backend , Level6 ) )
142
+ await bootstrap ( backend )
143
+ }
144
+ } )
145
+
146
+ afterEach ( async ( ) => {
147
+ if ( dir != null ) {
148
+ await cleanup ( dir )
154
149
}
155
150
} )
156
151
157
152
it ( 'should migrate keys and values backward' , async ( ) => {
158
- await migration . revert ( withLevels ( backends , Level6 ) , ( ) => { } )
153
+ ( { backends } = await setup ( {
154
+ dir,
155
+ prefix,
156
+ createBackends : {
157
+ createLevel : ( path ) => new Level6 ( path , {
158
+ valueEncoding : 'binary'
159
+ } )
160
+ }
161
+ } ) )
162
+
163
+ await migration . revert ( backends , ( ) => { } )
164
+
165
+ ; ( { backends } = await setup ( {
166
+ dir,
167
+ prefix,
168
+ createBackends : {
169
+ createLevel : ( path ) => new Level5 ( path , {
170
+ valueEncoding : 'binary'
171
+ } )
172
+ }
173
+ } ) )
159
174
160
175
for ( const backend of Object . values ( backends ) ) {
161
- await validate ( withLevel ( backend , Level5 ) )
176
+ await validate ( backend )
162
177
}
163
178
} )
164
179
} )
165
180
166
181
describe ( 'backwards using [email protected] ' , ( ) => {
182
+ /** @type {string } */
183
+ let dir
184
+ /** @type {import('../../src/types').Backends } */
185
+ let backends
186
+ /** @type {string } */
187
+ let prefix
188
+
167
189
beforeEach ( async ( ) => {
190
+ ( { dir, prefix, backends } = await setup ( {
191
+ createBackends : {
192
+ createLevel : ( path ) => new Level6 ( path , {
193
+ valueEncoding : 'binary'
194
+ } )
195
+ }
196
+ } ) )
197
+
168
198
for ( const backend of Object . values ( backends ) ) {
169
- await bootstrap ( withLevel ( backend , Level6 ) )
199
+ await bootstrap ( backend )
200
+ }
201
+ } )
202
+
203
+ afterEach ( async ( ) => {
204
+ if ( dir != null ) {
205
+ await cleanup ( dir )
170
206
}
171
207
} )
172
208
173
209
it ( 'should migrate keys and values backward' , async ( ) => {
174
- await migration . revert ( withLevels ( backends , Level5 ) , ( ) => { } )
210
+ ( { backends } = await setup ( {
211
+ dir,
212
+ prefix,
213
+ createBackends : {
214
+ createLevel : ( path ) => new Level5 ( path , {
215
+ valueEncoding : 'binary'
216
+ } )
217
+ }
218
+ } ) )
219
+
220
+ await migration . revert ( backends , ( ) => { } )
221
+
222
+ ; ( { backends } = await setup ( {
223
+ dir,
224
+ prefix,
225
+ createBackends : {
226
+ createLevel : ( path ) => new Level5 ( path , {
227
+ valueEncoding : 'binary'
228
+ } )
229
+ }
230
+ } ) )
175
231
176
232
for ( const backend of Object . values ( backends ) ) {
177
- await validate ( withLevel ( backend , Level5 ) )
233
+ await validate ( backend )
178
234
}
179
235
} )
180
236
} )
0 commit comments