Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit cef261f

Browse files
committed
gps: add tests for deleteEmptyDirs
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent c7c3fd8 commit cef261f

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

gps/prune_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,3 +617,98 @@ func pruneVendorDirsTestCase(tc fsTestCase) func(*testing.T) {
617617
tc.assert(t)
618618
}
619619
}
620+
621+
func TestDeleteEmptyDirs(t *testing.T) {
622+
testcases := []struct {
623+
name string
624+
fs fsTestCase
625+
}{
626+
{
627+
name: "empty-dir",
628+
fs: fsTestCase{
629+
before: filesystemState{
630+
dirs: []string{
631+
"pkg1",
632+
},
633+
},
634+
after: filesystemState{},
635+
},
636+
},
637+
{
638+
name: "nested-empty-dirs",
639+
fs: fsTestCase{
640+
before: filesystemState{
641+
dirs: []string{
642+
"pkg1",
643+
"pkg1/pkg2",
644+
},
645+
},
646+
after: filesystemState{},
647+
},
648+
},
649+
{
650+
name: "non-empty-dir",
651+
fs: fsTestCase{
652+
before: filesystemState{
653+
dirs: []string{
654+
"pkg1",
655+
},
656+
files: []string{
657+
"pkg1/file1",
658+
},
659+
},
660+
after: filesystemState{
661+
dirs: []string{
662+
"pkg1",
663+
},
664+
files: []string{
665+
"pkg1/file1",
666+
},
667+
},
668+
},
669+
},
670+
{
671+
name: "mixed-dirs",
672+
fs: fsTestCase{
673+
before: filesystemState{
674+
dirs: []string{
675+
"pkg1",
676+
"pkg1/pkg2",
677+
},
678+
files: []string{
679+
"pkg1/file1",
680+
},
681+
},
682+
after: filesystemState{
683+
dirs: []string{
684+
"pkg1",
685+
},
686+
files: []string{
687+
"pkg1/file1",
688+
},
689+
},
690+
},
691+
},
692+
}
693+
694+
for _, tc := range testcases {
695+
t.Run(tc.name, func(t *testing.T) {
696+
h := test.NewHelper(t)
697+
h.Cleanup()
698+
h.TempDir(".")
699+
700+
tc.fs.before.root = h.Path(".")
701+
tc.fs.after.root = h.Path(".")
702+
703+
if err := tc.fs.before.setup(); err != nil {
704+
t.Fatal("unexpected error in fs setup: ", err)
705+
}
706+
707+
if err := deleteEmptyDirs(tc.fs.before); err != nil {
708+
t.Fatal("unexpected error in deleteEmptyDirs: ", err)
709+
}
710+
711+
tc.fs.assert(t)
712+
})
713+
}
714+
}

0 commit comments

Comments
 (0)