TestWriteFileMkdirErrorWhenParentIsFile checks the (mkdir error) branch: a MkdirAll failure must surface in the output string (bash convention), never as a Go error. A file in the path triggers it; a read-only dir would not, since tests run as root and root bypasses directory permission bits.
(t *testing.T)
| 50 | // as a Go error. A file in the path triggers it; a read-only dir would not, |
| 51 | // since tests run as root and root bypasses directory permission bits. |
| 52 | func TestWriteFileMkdirErrorWhenParentIsFile(t *testing.T) { |
| 53 | dir := t.TempDir() |
| 54 | blocker := filepath.Join(dir, "iam-a-file") |
| 55 | if err := os.WriteFile(blocker, []byte("x"), 0o644); err != nil { |
| 56 | t.Fatal(err) |
| 57 | } |
| 58 | // blocker is a file, so MkdirAll(blocker/sub) must fail. |
| 59 | got := WriteFile(filepath.Join(blocker, "sub", "out.txt"), "data") |
| 60 | if !strings.HasPrefix(got, "(mkdir error:") { |
| 61 | t.Fatalf("expected (mkdir error: ...) string, got %q", got) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // TestWriteFileWriteErrorWhenTargetIsDir checks the (write error) branch: |
| 66 | // writing to an existing directory fails at os.WriteFile, and the error must |
nothing calls this directly
no test coverage detected