aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-02-25 09:44:35 -0800
committerJosh Bleecher Snyder <josharian@gmail.com>2021-03-11 18:25:41 +0000
commit1853411d8376570295711f9084d494d458822578 (patch)
tree8c1af2c5e28d544e7b7b1810ce98046bdd83a447 /src/testing
parentbbf79793bdeda04d520377406024d7bb66aa62dc (diff)
downloadgo-1853411d8376570295711f9084d494d458822578.tar.gz
go-1853411d8376570295711f9084d494d458822578.zip
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>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/fstest/testfs.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go
index 736bbf0590..89c5fa19af 100644
--- a/src/testing/fstest/testfs.go
+++ b/src/testing/fstest/testfs.go
@@ -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()