1
0
mirror of https://github.com/golang/go synced 2024-11-19 05:54:44 -07:00

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/40914
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Mostyn Bramley-Moore 2017-04-17 21:01:10 +02:00 committed by Brad Fitzpatrick
parent 73f283f4c8
commit 2c1bff6e06

View File

@ -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)