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

Function TestAppendFile_AppendsAllItsInputToSpecifiedFile

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

Source from the content-addressed store, hash-verified

1475}
1476
1477func TestAppendFile_AppendsAllItsInputToSpecifiedFile(t *testing.T) {
1478 t.Parallel()
1479 orig := "Hello, world"
1480 path := t.TempDir() + "/" + t.Name()
1481 _, err := script.Echo(orig).WriteFile(path)
1482 if err != nil {
1483 t.Fatal(err)
1484 }
1485 extra := " and goodbye"
1486 wrote, err := script.Echo(extra).AppendFile(path)
1487 if err != nil {
1488 t.Fatal(err)
1489 }
1490 if int(wrote) != len(extra) {
1491 t.Fatalf("want %d bytes written, got %d", len(extra), int(wrote))
1492 }
1493 // check file contains both contents
1494 got, err := script.File(path).String()
1495 if err != nil {
1496 t.Fatal(err)
1497 }
1498 if got != orig+extra {
1499 t.Errorf("want %q, got %q", orig+extra, got)
1500 }
1501}
1502
1503func TestAppendFile_ReturnsBytesWrittenAndErrorGivenReadErrorOnPipe(t *testing.T) {
1504 t.Parallel()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…