os.Stat: returned error on nonexistent path did not satisfy IsNotExist

Add direct test for the problem to make the fix commit clearer.

Noticed while implementing MkdirTemp on mac; the upstream tests for MkdirTemp fail without this.
This commit is contained in:
Dan Kegel
2021-12-12 15:16:52 -08:00
committed by Ron Evans
parent 1f6b4a5e7b
commit d30f8b6ed6
2 changed files with 13 additions and 2 deletions
+11
View File
@@ -4,6 +4,7 @@ package os_test
import (
. "os"
"path/filepath"
"strconv"
"testing"
"time"
@@ -31,6 +32,16 @@ func TestMkdir(t *testing.T) {
}
}
func TestStatBadDir(t *testing.T) {
dir := TempDir()
badDir := filepath.Join(dir, "not-exist/really-not-exist")
_, err := Stat(badDir)
// TODO: PathError moved to io/fs in go 1.16; fix next line once we drop go 1.15 support.
if pe, ok := err.(*PathError); !ok || !IsNotExist(err) || pe.Path != badDir {
t.Errorf("Mkdir error = %#v; want PathError for path %q satisifying IsNotExist", err, badDir)
}
}
func writeFile(t *testing.T, fname string, flag int, text string) string {
f, err := OpenFile(fname, flag, 0666)
if err != nil {