From: Mostyn Bramley-Moore Date: Mon, 17 Apr 2017 19:01:10 +0000 (+0200) Subject: io/ioutil: make TestTempFile more robust X-Git-Tag: go1.9beta1~662 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2c1bff6e0681ff2cace0f69c28b05f47d4262aa3;p=gostls13.git 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/io/ioutil/tempfile_test.go b/src/io/ioutil/tempfile_test.go index 6a70aedc32..9d54bad2ff 100644 --- a/src/io/ioutil/tempfile_test.go +++ b/src/io/ioutil/tempfile_test.go @@ -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)