}
}
-type openErrorTest struct {
- path string
- mode int
- error error
-}
+func TestOpenError(t *testing.T) {
+ t.Parallel()
+
+ dir := t.TempDir()
+ if err := WriteFile(filepath.Join(dir, "is-a-file"), nil, 0o666); err != nil {
+ t.Fatal(err)
+ }
+ if err := Mkdir(filepath.Join(dir, "is-a-dir"), 0o777); err != nil {
+ t.Fatal(err)
+ }
-var openErrorTests = []openErrorTest{
- {
- sfdir + "/no-such-file",
+ for _, tt := range []struct {
+ path string
+ mode int
+ error error
+ }{{
+ "no-such-file",
O_RDONLY,
syscall.ENOENT,
- },
- {
- sfdir,
+ }, {
+ "is-a-dir",
O_WRONLY,
syscall.EISDIR,
- },
- {
- sfdir + "/" + sfname + "/no-such-file",
+ }, {
+ "is-a-file/no-such-file",
O_WRONLY,
syscall.ENOTDIR,
- },
-}
-
-func TestOpenError(t *testing.T) {
- t.Parallel()
-
- for _, tt := range openErrorTests {
- f, err := OpenFile(tt.path, tt.mode, 0)
+ }} {
+ path := filepath.Join(dir, tt.path)
+ f, err := OpenFile(path, tt.mode, 0)
if err == nil {
t.Errorf("Open(%q, %d) succeeded", tt.path, tt.mode)
f.Close()