MCPcopy Create free account
hub / github.com/github/gh-aw / TestCopyFileContents

Function TestCopyFileContents

pkg/fileutil/fileutil_test.go:411–440  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

409}
410
411func TestCopyFileContents(t *testing.T) {
412 t.Run("returns close error after successful sync", func(t *testing.T) {
413 closeErr := errors.New("close failed")
414 out := &stubSyncWriteCloser{closeErr: closeErr}
415
416 err := copyFileContents(strings.NewReader("hello"), out, filepath.Join(t.TempDir(), "dst.txt"))
417
418 require.ErrorIs(t, err, closeErr)
419 assert.Equal(t, 1, out.closeCalls, "destination should be closed once")
420 assert.Equal(t, "hello", out.String(), "content should be copied before close")
421 })
422
423 t.Run("preserves copy error and closes destination once", func(t *testing.T) {
424 writeErr := errors.New("write failed")
425 closeErr := errors.New("close failed")
426 out := &stubSyncWriteCloser{
427 writeErr: writeErr,
428 closeErr: closeErr,
429 }
430
431 dst := filepath.Join(t.TempDir(), "dst.txt")
432 require.NoError(t, os.WriteFile(dst, []byte("partial"), 0600), "Should create destination placeholder")
433
434 err := copyFileContents(strings.NewReader("hello"), out, dst)
435
436 require.ErrorIs(t, err, writeErr)
437 assert.Equal(t, 1, out.closeCalls, "destination should be closed once during cleanup")
438 assert.NoFileExists(t, dst, "partial destination should be removed after copy failure")
439 })
440}
441
442func TestValidatePathWithinBase(t *testing.T) {
443 base := t.TempDir()

Callers

nothing calls this directly

Calls 3

StringMethod · 0.95
copyFileContentsFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected