@@ -169,6 +169,114 @@ describe('Test cache layer loader', () => {
169169 // Set 50s timeout to test cache loader export and load data
170170 50 * 10000
171171 ) ;
172+ it (
173+ 'Should remove the other parquet files after executing export' ,
174+ async ( ) => {
175+ // Arrange
176+ const templateName = 'template-1' ;
177+ const cache = {
178+ cacheTableName : 'employees' ,
179+ sql : sinon . default . stub ( ) as any ,
180+ profile : profiles [ 0 ] . name ,
181+ folderSubpath : '2023' ,
182+ } as CacheLayerInfo ;
183+ const { profile, cacheTableName, folderSubpath } = cache ;
184+ const dir = path . resolve (
185+ folderPath ,
186+ templateName ,
187+ profile ,
188+ cacheTableName ,
189+ folderSubpath !
190+ ) ;
191+ const loader = new CacheLayerLoader ( options , stubFactory as any ) ;
192+ await loader . load ( templateName , cache ) ;
193+ expect ( fs . readdirSync ( dir ) . length ) . toBeGreaterThan ( 0 ) ;
194+
195+ // Act
196+ cache . folderSubpath = '2024' ;
197+ await loader . load ( templateName , cache ) ;
198+
199+ // Assert
200+ const newDir = path . resolve (
201+ folderPath ,
202+ templateName ,
203+ profile ,
204+ cacheTableName ,
205+ '2024' !
206+ ) ;
207+ expect ( fs . readdirSync ( dir ) . length ) . toEqual ( 0 ) ;
208+ expect ( fs . readdirSync ( newDir ) . length ) . toBeGreaterThan ( 0 ) ;
209+ } ,
210+ // Set 50s timeout to test cache loader export and load data
211+ 50 * 10000
212+ ) ;
213+ it (
214+ 'Should not remove files if parquet files were reused' ,
215+ async ( ) => {
216+ const templateName = 'template-1' ;
217+ const cache = {
218+ cacheTableName : 'employees' ,
219+ sql : sinon . default . stub ( ) as any ,
220+ profile : profiles [ 0 ] . name ,
221+ folderSubpath : '2023' ,
222+ } as CacheLayerInfo ;
223+ // Arrange
224+ const { profile, cacheTableName, folderSubpath } = cache ;
225+ const dir = path . resolve (
226+ folderPath ,
227+ templateName ,
228+ profile ,
229+ cacheTableName ,
230+ folderSubpath !
231+ ) ;
232+ const loader = new CacheLayerLoader ( options , stubFactory as any ) ;
233+ await loader . load ( templateName , cache ) ;
234+ const parquetFiles = fs . readdirSync ( dir ) ;
235+
236+ // Act
237+ await loader . load ( templateName , cache ) ;
238+
239+ // Assert
240+ // expect parquetFiles is the same
241+ expect ( fs . readdirSync ( dir ) ) . toEqual ( parquetFiles ) ;
242+ } ,
243+ // Set 50s timeout to test cache loader export and load data
244+ 50 * 10000
245+ ) ;
246+
247+ it (
248+ 'Should remove parquet files of its own folder.' ,
249+ async ( ) => {
250+ // Arrange
251+ const templateName = 'template-1' ;
252+ const cache = {
253+ cacheTableName : 'employees' ,
254+ sql : sinon . default . stub ( ) as any ,
255+ profile : profiles [ 0 ] . name ,
256+ folderSubpath : '2023' ,
257+ } as CacheLayerInfo ;
258+ const { profile, cacheTableName, folderSubpath } = cache ;
259+ const loader = new CacheLayerLoader ( options , stubFactory as any ) ;
260+ await loader . load ( templateName , cache ) ;
261+ const dirPath = path . resolve (
262+ folderPath ,
263+ templateName ,
264+ profile ,
265+ cacheTableName ,
266+ folderSubpath !
267+ ) ;
268+ expect ( fs . readdirSync ( dirPath ) . length ) . toBeGreaterThan ( 0 ) ;
269+
270+ // Act :load another cache table
271+ cache . cacheTableName = 'another_employees' ;
272+ await loader . load ( templateName , cache ) ;
273+
274+ // Assert
275+ expect ( fs . readdirSync ( dirPath ) . length ) . toBeGreaterThan ( 0 ) ;
276+ } ,
277+ // Set 50s timeout to test cache loader export and load data
278+ 50 * 10000
279+ ) ;
172280} ) ;
173281
174282async function createParquetFile ( path : string , fileName : string ) {
0 commit comments