]> Cypherpunks repositories - gostls13.git/commitdiff
testing/fstest,os: clarify racy behavior of TestFS
authorAustin Clements <austin@google.com>
Thu, 7 Jan 2021 22:50:14 +0000 (17:50 -0500)
committerAustin Clements <austin@google.com>
Fri, 8 Jan 2021 16:34:00 +0000 (16:34 +0000)
The testing.TestFS function assumes that the file system it's testing
doesn't change under it. Clarify this in the documentation and fix the
use of os.TestDirFS that's currently susceptible to this race.

Fixes #42637.

Change-Id: Ia7792380726177f8953d150ee87381b66cb01cb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/282452
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/os/os_test.go
src/os/testdata/dirfs/a [new file with mode: 0644]
src/os/testdata/dirfs/b [new file with mode: 0644]
src/os/testdata/dirfs/dir/x [new file with mode: 0644]
src/testing/fstest/testfs.go

index 765797f5fbd525770da60d3d9a953975189911e3..d2e8ed5d8221d293eb729aec708f8cfd866f85aa 100644 (file)
@@ -2687,7 +2687,7 @@ func TestOpenFileKeepsPermissions(t *testing.T) {
 }
 
 func TestDirFS(t *testing.T) {
-       if err := fstest.TestFS(DirFS("./signal"), "signal.go", "internal/pty/pty.go"); err != nil {
+       if err := fstest.TestFS(DirFS("./testdata/dirfs"), "a", "b", "dir/x"); err != nil {
                t.Fatal(err)
        }
 }
diff --git a/src/os/testdata/dirfs/a b/src/os/testdata/dirfs/a
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/os/testdata/dirfs/b b/src/os/testdata/dirfs/b
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/os/testdata/dirfs/dir/x b/src/os/testdata/dirfs/dir/x
new file mode 100644 (file)
index 0000000..e69de29
index 4da6f04eed5d59d7d09998899e8f0189ccfae2e6..a7f8007333e310eef526c61e667b789b2f125301 100644 (file)
@@ -24,6 +24,7 @@ import (
 // It also checks that the file system contains at least the expected files.
 // As a special case, if no expected files are listed, fsys must be empty.
 // Otherwise, fsys must only contain at least the listed files: it can also contain others.
+// The contents of fsys must not change concurrently with TestFS.
 //
 // If TestFS finds any misbehaviors, it returns an error reporting all of them.
 // The error text spans multiple lines, one per detected misbehavior.