@@ -140,15 +140,64 @@ export class R2Provider implements Provider {
140140 result = await s3Provider . readDirectory ( path ) ;
141141 }
142142
143- // Temporary: compare S3/cached listing result to what the KV provider returns
143+ // Temporary: compare S3/cached listing result to what the KV provider returns.
144+ // We expect a little difference in last modified dates, but otherwise things should match up
144145 if ( this . ctx . env . ENVIRONMENT !== 'e2e-tests' ) {
145146 this . ctx . execution . waitUntil (
146147 ( async ( ) : Promise < undefined > => {
147148 try {
148149 const kvResult = await kvProvider . readDirectory ( path ) ;
149150
150- if ( JSON . stringify ( kvResult ) !== JSON . stringify ( result ) ) {
151- throw new Error ( 'listing mismatch' ) ;
151+ if ( result === undefined ) {
152+ if ( kvResult !== undefined ) {
153+ throw new Error ( 'non-existent directory exists in kv' ) ;
154+ }
155+
156+ // Directory doesn't exist in both sources, nothing further to do
157+ return ;
158+ }
159+
160+ if ( kvResult === undefined ) {
161+ // Directory exists in r2 but not in kv
162+ throw new Error ( 'kv missing directory' ) ;
163+ }
164+
165+ if ( result . hasIndexHtmlFile !== kvResult . hasIndexHtmlFile ) {
166+ throw new Error ( 'hasIndexHtmlFile mismatch' ) ;
167+ }
168+
169+ // Both subdirectory properties should be indentical
170+ if (
171+ JSON . stringify ( result . subdirectories ) !==
172+ JSON . stringify ( kvResult . subdirectories )
173+ ) {
174+ throw new Error ( 'directories mismatch' ) ;
175+ }
176+
177+ // We should have the same number of files in both
178+ if ( result . files . length !== kvResult . files . length ) {
179+ throw new Error (
180+ `file count mismatch: ${ result . files . length - kvResult . files . length } `
181+ ) ;
182+ }
183+
184+ // R2 & KV file listings should be identical besides kv having
185+ // slightly higher precise timestamps
186+ for ( let i = 0 ; i < result . files . length ; i ++ ) {
187+ const r2File = result . files [ i ] ;
188+ const kvFile = kvResult . files [ i ] ;
189+
190+ if ( r2File . name !== kvFile . name ) {
191+ throw new Error (
192+ `file name mismatch: ${ r2File . name } ${ kvFile . name } `
193+ ) ;
194+ }
195+
196+ if ( r2File . size !== kvFile . size ) {
197+ throw new Error (
198+ `file size mismatch: ${ r2File . size } ${ kvFile . size } `
199+ ) ;
200+ }
152201 }
153202 } catch ( err ) {
154203 // Either an error when hitting KV or a mismatch between S3 & KV
0 commit comments