Commit 2c1bff6e authored by Mostyn Bramley-Moore's avatar Mostyn Bramley-Moore Committed by Brad Fitzpatrick

io/ioutil: make TestTempFile more robust

The first part of this test tries to confirm that we can't create
a TempFile in a non-existent directory, but does not ensure that
the non-existent directory really does not exist.  Instead, let's
create an empty temp directory, and use a non-existent subdir of
that.

Change-Id: I176f14ed5f5a2d7a8c29d8f6949755db69d7dbb6
Reviewed-on: https://go-review.googlesource.com/40914Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 73f283f4
......@@ -12,12 +12,19 @@ import (
)
func TestTempFile(t *testing.T) {
f, err := TempFile("/_not_exists_", "foo")
dir, err := TempDir("", "TestTempFile_BadDir")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
nonexistentDir := filepath.Join(dir, "_not_exists_")
f, err := TempFile(nonexistentDir, "foo")
if f != nil || err == nil {
t.Errorf("TempFile(`/_not_exists_`, `foo`) = %v, %v", f, err)
t.Errorf("TempFile(%q, `foo`) = %v, %v", nonexistentDir, f, err)
}
dir := os.TempDir()
dir = os.TempDir()
f, err = TempFile(dir, "ioutil_test")
if f == nil || err != nil {
t.Errorf("TempFile(dir, `ioutil_test`) = %v, %v", f, err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment