MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestWriteFileMkdirErrorWhenParentIsFile

Function TestWriteFileMkdirErrorWhenParentIsFile

internal/tools/write_test.go:52–63  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
52func 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

Callers

nothing calls this directly

Calls 1

WriteFileFunction · 0.85

Tested by

no test coverage detected