MCPcopy
hub / github.com/bitfield/script / TestWriteFile_TruncatesExistingFile

Function TestWriteFile_TruncatesExistingFile

script_test.go:1742–1769  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1740}
1741
1742func TestWriteFile_TruncatesExistingFile(t *testing.T) {
1743 t.Parallel()
1744 want := "Hello, world"
1745 path := t.TempDir() + "/" + t.Name()
1746 // write some data first so we can check for truncation
1747 data := make([]byte, 15)
1748 err := os.WriteFile(path, data, 0o600)
1749 if err != nil {
1750 t.Fatal(err)
1751 }
1752 wrote, err := script.Echo(want).WriteFile(path)
1753 if err != nil {
1754 t.Fatal(err)
1755 }
1756 if int(wrote) != len(want) {
1757 t.Fatalf("want %d bytes written, got %d", len(want), int(wrote))
1758 }
1759 got, err := script.File(path).String()
1760 if err != nil {
1761 t.Fatal(err)
1762 }
1763 if got == want+"\x00\x00\x00" {
1764 t.Fatalf("file not truncated on write")
1765 }
1766 if got != want {
1767 t.Errorf("want %q, got %q", want, got)
1768 }
1769}
1770
1771func TestWithHTTPClient_SetsSuppliedClientOnPipe(t *testing.T) {
1772 t.Parallel()

Callers

nothing calls this directly

Calls 4

EchoFunction · 0.92
FileFunction · 0.92
WriteFileMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…