mirror of
https://github.com/golang/go
synced 2024-11-11 23:40:22 -07:00
testing/fstest: test that ReadDirFile on a non-dir fails
ReadDirFile implementations should return an error for non-directories. Change-Id: I99888562cb6cf829017904ae8c1e8887a416c4cd Reviewed-on: https://go-review.googlesource.com/c/go/+/296391 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
bbf79793bd
commit
1853411d83
@ -119,6 +119,9 @@ func (t *fsTester) openDir(dir string) fs.ReadDirFile {
|
||||
t.errorf("%s: Open: %v", dir, err)
|
||||
return nil
|
||||
}
|
||||
// It'd be nice to test here that f.Read fails, because f is a directory.
|
||||
// However, FreeBSD supports calling read on a directory.
|
||||
// See https://groups.google.com/g/golang-dev/c/rh8jwxyG1PQ.
|
||||
d, ok := f.(fs.ReadDirFile)
|
||||
if !ok {
|
||||
f.Close()
|
||||
@ -514,6 +517,12 @@ func (t *fsTester) checkFile(file string) {
|
||||
return
|
||||
}
|
||||
|
||||
if dir, ok := f.(fs.ReadDirFile); ok {
|
||||
if _, err := dir.ReadDir(-1); err == nil {
|
||||
t.errorf("%s: ReadDir of non-dir file should return an error", file)
|
||||
}
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
f.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user