@@ -776,3 +776,60 @@ func TestMemMapFsConfurrentMkdir(t *testing.T) {
776
776
t .Errorf ("found %d files, but expect %d" , len (foundFiles ), n )
777
777
}
778
778
}
779
+
780
+ func TestMemFsRenameDir (t * testing.T ) {
781
+ const srcPath = "/src"
782
+ const dstPath = "/dst"
783
+ const subDir = "dir"
784
+ const subFile = "file.txt"
785
+
786
+ fs := NewMemMapFs ()
787
+
788
+ err := fs .MkdirAll (srcPath + FilePathSeparator + subDir , 0777 )
789
+ if err != nil {
790
+ t .Fatalf ("MkDirAll failed: %s" , err )
791
+ }
792
+
793
+ f , err := fs .Create (srcPath + FilePathSeparator + subFile )
794
+ if err != nil {
795
+ t .Fatalf ("Create failed: %s" , err )
796
+ }
797
+ if err = f .Close (); err != nil {
798
+ t .Fatalf ("Close failed: %s" , err )
799
+ }
800
+
801
+ err = fs .Rename (srcPath , dstPath )
802
+ if err != nil {
803
+ t .Fatalf ("Rename failed: %s" , err )
804
+ }
805
+
806
+ _ , err = fs .Stat (srcPath + FilePathSeparator + subDir )
807
+ if err == nil {
808
+ t .Fatalf ("SubDir still exists in the source dir" )
809
+ }
810
+
811
+ _ , err = fs .Stat (srcPath + FilePathSeparator + subFile )
812
+ if err == nil {
813
+ t .Fatalf ("SubFile still exists in the source dir" )
814
+ }
815
+
816
+ _ , err = fs .Stat (dstPath + FilePathSeparator + subDir )
817
+ if err != nil {
818
+ t .Fatalf ("SubDir stat in the destination dir: %s" , err )
819
+ }
820
+
821
+ _ , err = fs .Stat (dstPath + FilePathSeparator + subFile )
822
+ if err != nil {
823
+ t .Fatalf ("SubFile stat in the destination dir: %s" , err )
824
+ }
825
+
826
+ err = fs .Mkdir (srcPath , 0777 )
827
+ if err != nil {
828
+ t .Fatalf ("Cannot recreate the source dir: %s" , err )
829
+ }
830
+
831
+ err = fs .Mkdir (srcPath + FilePathSeparator + subDir , 0777 )
832
+ if err != nil {
833
+ t .Errorf ("Cannot recreate the subdir in the source dir: %s" , err )
834
+ }
835
+ }
0 commit comments