feat: Start implementation of symlink support to readdir
This commit is contained in:
+201
-21
@@ -632,7 +632,7 @@ var readdirTests = []struct {
|
||||
open string
|
||||
args readdirArgs
|
||||
wantErr bool
|
||||
prepare func(afero.Fs) error
|
||||
prepare func(symFs) error
|
||||
check func([]os.FileInfo) error
|
||||
withCache bool
|
||||
withOsFs bool
|
||||
@@ -642,7 +642,7 @@ var readdirTests = []struct {
|
||||
"/",
|
||||
readdirArgs{-1},
|
||||
false,
|
||||
func(f afero.Fs) error { return nil },
|
||||
func(f symFs) error { return nil },
|
||||
func(f []os.FileInfo) error {
|
||||
if len(f) > 0 {
|
||||
return errors.New("found unexpected children in empty directory")
|
||||
@@ -658,7 +658,7 @@ var readdirTests = []struct {
|
||||
"",
|
||||
readdirArgs{-1},
|
||||
false,
|
||||
func(f afero.Fs) error { return nil },
|
||||
func(f symFs) error { return nil },
|
||||
func(f []os.FileInfo) error {
|
||||
if len(f) > 0 {
|
||||
return errors.New("found unexpected children in empty directory")
|
||||
@@ -674,7 +674,7 @@ var readdirTests = []struct {
|
||||
"/",
|
||||
readdirArgs{-1},
|
||||
false,
|
||||
func(f afero.Fs) error {
|
||||
func(f symFs) error {
|
||||
if _, err := f.Create("/test.txt"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -693,8 +693,8 @@ var readdirTests = []struct {
|
||||
}
|
||||
}
|
||||
|
||||
wantLength := len(f)
|
||||
gotLength := 1
|
||||
wantLength := len(wantNames)
|
||||
gotLength := len(f)
|
||||
if wantLength != gotLength {
|
||||
return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
}
|
||||
@@ -709,7 +709,7 @@ var readdirTests = []struct {
|
||||
"/",
|
||||
readdirArgs{-1},
|
||||
false,
|
||||
func(f afero.Fs) error {
|
||||
func(f symFs) error {
|
||||
if _, err := f.Create("/test.txt"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -738,8 +738,8 @@ var readdirTests = []struct {
|
||||
}
|
||||
}
|
||||
|
||||
wantLength := len(f)
|
||||
gotLength := 3
|
||||
wantLength := len(wantNames)
|
||||
gotLength := len(f)
|
||||
if wantLength != gotLength {
|
||||
return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
}
|
||||
@@ -754,7 +754,7 @@ var readdirTests = []struct {
|
||||
"/",
|
||||
readdirArgs{0},
|
||||
false,
|
||||
func(f afero.Fs) error {
|
||||
func(f symFs) error {
|
||||
if _, err := f.Create("/test.txt"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -783,8 +783,8 @@ var readdirTests = []struct {
|
||||
}
|
||||
}
|
||||
|
||||
wantLength := len(f)
|
||||
gotLength := 3
|
||||
wantLength := len(wantNames)
|
||||
gotLength := len(f)
|
||||
if wantLength != gotLength {
|
||||
return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
}
|
||||
@@ -799,7 +799,7 @@ var readdirTests = []struct {
|
||||
"/",
|
||||
readdirArgs{2},
|
||||
false,
|
||||
func(f afero.Fs) error {
|
||||
func(f symFs) error {
|
||||
if _, err := f.Create("/test.txt"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -828,8 +828,8 @@ var readdirTests = []struct {
|
||||
}
|
||||
}
|
||||
|
||||
wantLength := len(f)
|
||||
gotLength := 2
|
||||
wantLength := 2
|
||||
gotLength := len(f)
|
||||
if wantLength != gotLength {
|
||||
return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
}
|
||||
@@ -844,7 +844,7 @@ var readdirTests = []struct {
|
||||
"/mydir",
|
||||
readdirArgs{2},
|
||||
false,
|
||||
func(f afero.Fs) error {
|
||||
func(f symFs) error {
|
||||
if _, err := f.Create("/test.txt"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -876,8 +876,8 @@ var readdirTests = []struct {
|
||||
}
|
||||
}
|
||||
|
||||
wantLength := len(f)
|
||||
gotLength := 2
|
||||
wantLength := 2
|
||||
gotLength := len(f)
|
||||
if wantLength != gotLength {
|
||||
return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
}
|
||||
@@ -892,7 +892,7 @@ var readdirTests = []struct {
|
||||
"/mydir/nested",
|
||||
readdirArgs{3},
|
||||
false,
|
||||
func(f afero.Fs) error {
|
||||
func(f symFs) error {
|
||||
if _, err := f.Create("/test.txt"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -929,8 +929,8 @@ var readdirTests = []struct {
|
||||
}
|
||||
}
|
||||
|
||||
wantLength := len(f)
|
||||
gotLength := 3
|
||||
wantLength := len(wantNames)
|
||||
gotLength := len(f)
|
||||
if wantLength != gotLength {
|
||||
return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
}
|
||||
@@ -940,6 +940,186 @@ var readdirTests = []struct {
|
||||
true,
|
||||
true,
|
||||
},
|
||||
// {
|
||||
// "Can readdir 5 in /mydir/nested if there are multiple children and non-broken symlinks",
|
||||
// "/mydir/nested",
|
||||
// readdirArgs{5},
|
||||
// false,
|
||||
// func(f symFs) error {
|
||||
// if _, err := f.Create("/test.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if err := f.MkdirAll("/mydir/nested", os.ModePerm); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/asdf.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/hmm.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/hmm2.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if err := f.SymlinkIfPossible("/test.txt", "/mydir/nested/existingsymlink"); err != nil {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// if err := f.SymlinkIfPossible("/mydir/nested/hmm.txt", "/mydir/nested/existingsymlink2"); err != nil {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// },
|
||||
// func(f []os.FileInfo) error {
|
||||
// wantNames := map[string]struct{}{
|
||||
// "asdf.txt": {},
|
||||
// "hmm.txt": {},
|
||||
// "hmm2.txt": {},
|
||||
// "existingsymlink": {},
|
||||
// "existingsymlink2": {},
|
||||
// }
|
||||
|
||||
// for _, info := range f {
|
||||
// name, ok := wantNames[info.Name()]
|
||||
// if !ok {
|
||||
// return fmt.Errorf("could not find file or directory with name %v", name)
|
||||
// }
|
||||
// }
|
||||
|
||||
// wantLength := len(wantNames)
|
||||
// gotLength := len(f)
|
||||
// if wantLength != gotLength {
|
||||
// return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// },
|
||||
// true,
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "Can readdir 5 in /mydir/nested if there are multiple children and broken symlinks",
|
||||
// "/mydir/nested",
|
||||
// readdirArgs{5},
|
||||
// false,
|
||||
// func(f symFs) error {
|
||||
// if err := f.MkdirAll("/mydir/nested", os.ModePerm); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/asdf.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/hmm.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/hmm2.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if err := f.SymlinkIfPossible("/mydir/nested/hmm2.txt", "/mydir/nested/existingsymlink"); err != nil {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// if err := f.SymlinkIfPossible("/test.txt", "/mydir/nested/brokensymlink"); err != nil {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// },
|
||||
// func(f []os.FileInfo) error {
|
||||
// wantNames := map[string]struct{}{
|
||||
// "asdf.txt": {},
|
||||
// "hmm.txt": {},
|
||||
// "hmm2.txt": {},
|
||||
// "existingsymlink": {},
|
||||
// "brokensymlink": {},
|
||||
// }
|
||||
|
||||
// for _, info := range f {
|
||||
// name, ok := wantNames[info.Name()]
|
||||
// if !ok {
|
||||
// return fmt.Errorf("could not find file or directory with name %v", name)
|
||||
// }
|
||||
// }
|
||||
|
||||
// wantLength := len(wantNames)
|
||||
// gotLength := len(f)
|
||||
// if wantLength != gotLength {
|
||||
// return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// },
|
||||
// true,
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "Can readdir 4 in /existingsymlink if there are multiple children and symlinks",
|
||||
// "/existingsymlink",
|
||||
// readdirArgs{4},
|
||||
// false,
|
||||
// func(f symFs) error {
|
||||
// if err := f.MkdirAll("/mydir/nested", os.ModePerm); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/asdf.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/hmm.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if _, err := f.Create("/mydir/nested/hmm2.txt"); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if err := f.SymlinkIfPossible("/test.txt", "/mydir/nested/brokensymlink"); err != nil {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// if err := f.SymlinkIfPossible("/mydir/nested", "/existingsymlink"); err != nil {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// },
|
||||
// func(f []os.FileInfo) error {
|
||||
// wantNames := map[string]struct{}{
|
||||
// "asdf.txt": {},
|
||||
// "hmm.txt": {},
|
||||
// "hmm2.txt": {},
|
||||
// "brokensymlink": {},
|
||||
// }
|
||||
|
||||
// for _, info := range f {
|
||||
// name, ok := wantNames[info.Name()]
|
||||
// if !ok {
|
||||
// return fmt.Errorf("could not find file or directory with name %v", name)
|
||||
// }
|
||||
// }
|
||||
|
||||
// wantLength := len(f)
|
||||
// gotLength := 3
|
||||
// if wantLength != gotLength {
|
||||
// return fmt.Errorf("invalid amount of children, got %v, want %v", gotLength, wantLength)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// },
|
||||
// true,
|
||||
// true,
|
||||
// },
|
||||
}
|
||||
|
||||
func TestFile_Readdir(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user