Skip to content

Commit e73fca5

Browse files
committed
improving fileWorkspaceMap listing test coverage
1 parent 9f08e39 commit e73fca5

2 files changed

Lines changed: 189 additions & 17 deletions

File tree

src/main/java/picoded/dstack/core/Core_FileWorkspaceMap.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ protected Set<String> backend_filterPathSet(final Set<String> rawSet, final Stri
588588
// If folder path match - store it - maybe?
589589
String subPath = key.substring(searchPathLen);
590590

591+
// Skip the root folder of a subpath
592+
if( subPath.equals("") || subPath.equals("/") ) {
593+
continue;
594+
}
595+
591596
// No filtering is needed, store and continue
592597
if (maxDepth <= 0 && minDepth <= 0) {
593598
// Does no checks, add and continue

src/test/java/picoded/dstack/struct/simple/StructSimple_FileWorkspaceMap_test.java

Lines changed: 184 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ public void fileWrite_andFolderCopy() {
330330
//
331331
//-----------------------------------------------------------------------------------
332332

333-
@Test
334-
public void getPathSetLookup() {
333+
// Setup a predefined fileworkspace, for path set loookup testing
334+
public FileWorkspace getPathSetLookup_setup() {
335335
// Get the file workspace to use
336336
FileWorkspace fileWorkspace = testObj.newEntry();
337337
assertNotNull(fileWorkspace);
@@ -348,25 +348,192 @@ public void getPathSetLookup() {
348348
fileWorkspace.writeString("test/d1/file.txt", "anything");
349349
fileWorkspace.writeString("test/d2/file1.txt", "anything");
350350
fileWorkspace.writeString("test/d2/file2.txt", "anything");
351-
352-
// List all files and folders
353-
// this includes, 5 files, and 3 folders (test/, test/d1/, test/d2/)
354-
assertEquals(8, fileWorkspace.getFileAndFolderPathSet(null, -1, -1).size());
355-
assertEquals(8, fileWorkspace.getFileAndFolderPathSet("", -1, -1).size());
356-
assertEquals(8, fileWorkspace.getFileAndFolderPathSet("/", -1, -1).size());
357351

358-
assertEquals(3, fileWorkspace.getFolderPathSet("", -1, -1).size());
359-
assertEquals(5, fileWorkspace.getFilePathSet("", -1, -1).size());
352+
// And return
353+
return fileWorkspace;
354+
}
360355

361-
// List the `test/` folder
362-
assertEquals(1, fileWorkspace.getFileAndFolderPathSet(null).size());
363-
assertEquals(1, fileWorkspace.getFileAndFolderPathSet("").size());
364-
assertEquals(1, fileWorkspace.getFileAndFolderPathSet("/").size());
365-
assertEquals(1, fileWorkspace.getFolderPathSet("").size());
356+
// Just perform and validate setup
357+
@Test
358+
public void getPathSetLookup_setupTest() {
359+
// Get the file workspace to use
360+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
361+
assertNotNull(fileWorkspace);
362+
}
366363

367-
// The `test/` is not a file, hence 0
368-
assertEquals(0, fileWorkspace.getFilePathSet("").size());
364+
// List all files and folders
365+
// this includes, 5 files, and 3 folders (test/, test/d1/, test/d2/)
366+
//
367+
// See `getPathSetLookup_setup` for setup code
368+
@Test
369+
public void getPathSetLookup_fullSet() {
370+
// Get the file workspace to use
371+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
372+
373+
// Test set to use for comparision
374+
Set<String> testFileSet = new HashSet<>();
375+
Set<String> testDirSet = new HashSet<>();
376+
Set<String> testFullSet = new HashSet<>();
377+
378+
// Test files
379+
testFileSet.add("test/one.txt");
380+
testFileSet.add("test/two.txt");
381+
testFileSet.add("test/d1/file.txt");
382+
testFileSet.add("test/d2/file1.txt");
383+
testFileSet.add("test/d2/file2.txt");
384+
385+
// Test dirs
386+
testDirSet.add("test/");
387+
testDirSet.add("test/d1/");
388+
testDirSet.add("test/d2/");
369389

390+
// Full set
391+
testFullSet.addAll(testFileSet);
392+
testFullSet.addAll(testDirSet);
393+
394+
// Test it !
395+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet(null, -1, -1));
396+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("", -1, -1));
397+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("/", -1, -1));
398+
assertEquals(testDirSet, fileWorkspace.getFolderPathSet("", -1, -1));
399+
assertEquals(testFileSet, fileWorkspace.getFilePathSet("", -1, -1));
400+
}
401+
402+
// List all files and folders, with limits
403+
//
404+
// See `getPathSetLookup_setup` for setup code
405+
@Test
406+
public void getPathSetLookup_fullSet_withLimit() {
407+
// Get the file workspace to use
408+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
409+
410+
// Test set to use for comparision
411+
Set<String> testFileSet = new HashSet<>();
412+
Set<String> testDirSet = new HashSet<>();
413+
Set<String> testFullSet = new HashSet<>();
414+
415+
// Test files
416+
testFileSet.add("test/one.txt");
417+
testFileSet.add("test/two.txt");
418+
419+
// Test dirs
420+
testDirSet.add("test/");
421+
testDirSet.add("test/d1/");
422+
testDirSet.add("test/d2/");
423+
424+
// Full set
425+
testFullSet.addAll(testFileSet);
426+
testFullSet.addAll(testDirSet);
427+
428+
// Test it !
429+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet(null, -1, 2));
430+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("", -1, 2));
431+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("/", -1, 2));
432+
assertEquals(testDirSet, fileWorkspace.getFolderPathSet("", -1, 2));
433+
assertEquals(testFileSet, fileWorkspace.getFilePathSet("", -1, 2));
434+
}
435+
436+
// List all files and folders from the `test/` dir
437+
//
438+
// See `getPathSetLookup_setup` for setup code
439+
@Test
440+
public void getPathSetLookup_testDir_fullSet() {
441+
// Get the file workspace to use
442+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
443+
444+
// Test set to use for comparision
445+
Set<String> testFileSet = new HashSet<>();
446+
Set<String> testDirSet = new HashSet<>();
447+
Set<String> testFullSet = new HashSet<>();
448+
449+
// Test files
450+
testFileSet.add("one.txt");
451+
testFileSet.add("two.txt");
452+
testFileSet.add("d1/file.txt");
453+
testFileSet.add("d2/file1.txt");
454+
testFileSet.add("d2/file2.txt");
455+
456+
// Test dirs
457+
testDirSet.add("d1/");
458+
testDirSet.add("d2/");
459+
460+
// Full set
461+
testFullSet.addAll(testFileSet);
462+
testFullSet.addAll(testDirSet);
463+
464+
// Test it !
465+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("test/", -1, -1));
466+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("test", -1, -1));
467+
assertEquals(testDirSet, fileWorkspace.getFolderPathSet("test", -1, -1));
468+
assertEquals(testFileSet, fileWorkspace.getFilePathSet("test", -1, -1));
469+
}
470+
471+
// List all files and folders from the `/` dir
472+
//
473+
// See `getPathSetLookup_setup` for setup code
474+
@Test
475+
public void getPathSetLookup_listRoot() {
476+
// Get the file workspace to use
477+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
478+
479+
// Test set to use for comparision
480+
Set<String> testFileSet = new HashSet<>();
481+
Set<String> testDirSet = new HashSet<>();
482+
Set<String> testFullSet = new HashSet<>();
483+
484+
// Test files
485+
// -- there is none
486+
487+
// Test dirs
488+
testDirSet.add("test/");
489+
490+
// Full set
491+
testFullSet.addAll(testFileSet);
492+
testFullSet.addAll(testDirSet);
493+
494+
// Test it !
495+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("/"));
496+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet(""));
497+
assertEquals(testDirSet, fileWorkspace.getFolderPathSet(""));
498+
assertEquals(testFileSet, fileWorkspace.getFilePathSet(""));
499+
}
500+
501+
// List all files and folders from the `test/d2/` dir
502+
//
503+
// See `getPathSetLookup_setup` for setup code
504+
@Test
505+
public void getPathSetLookup_testDir_d2() {
506+
// Get the file workspace to use
507+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
508+
509+
// Test set to use for comparision
510+
Set<String> testFileSet = new HashSet<>();
511+
Set<String> testDirSet = new HashSet<>();
512+
Set<String> testFullSet = new HashSet<>();
513+
514+
// Test files
515+
testFileSet.add("file1.txt");
516+
testFileSet.add("file2.txt");
517+
518+
// Test dirs
519+
// -- there is none
520+
521+
// Full set
522+
testFullSet.addAll(testFileSet);
523+
testFullSet.addAll(testDirSet);
524+
525+
// Test it !
526+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("test/d2/", -1, -1));
527+
assertEquals(testFullSet, fileWorkspace.getFileAndFolderPathSet("test/d2", -1, -1));
528+
assertEquals(testDirSet, fileWorkspace.getFolderPathSet("test/d2/", -1, -1));
529+
assertEquals(testFileSet, fileWorkspace.getFilePathSet("test/d2/", -1, -1));
530+
}
531+
532+
@Test
533+
public void getPathSetLookup() {
534+
// Get the file workspace to use
535+
FileWorkspace fileWorkspace = getPathSetLookup_setup();
536+
370537
// List files & folders in the `test/` sub folders
371538
assertEquals(4, fileWorkspace.getFileAndFolderPathSet("test").size());
372539
assertEquals(2, fileWorkspace.getFilePathSet("test").size());

0 commit comments

Comments
 (0)