func (s *memFileTest) TestCopyToFileOS() {
	expectedText := "Hello World!"
	var osFile vfs.File
	var err error
	dir, err := ioutil.TempDir("", "osDir")
	if err != nil {
		log.Fatal(err)
	}
	osFileName := filepath.Join(dir, "osFile.txt")
	osFile, err = backend.Backend(_os.Scheme).NewFile("", osFileName)
	s.NoError(err, "unexpected error creating osFile")
	_, err = osFile.Write(make([]byte, 0))
	s.NoError(err, "unexpected error writing zero bytes to osFile")
	num, err := s.testFile.Write([]byte(expectedText))
	s.False(num == 0)
	s.NoError(err, "no error expected from Write but got one")
	s.NoError(s.testFile.Close(), "unexpected error closing a  file")
	err = s.testFile.CopyToFile(osFile)
	s.NoError(err, "copy to file failed unexpectedly")
	s.NoError(osFile.Close(), "unexpected error closing a  file")
	size1, err := s.testFile.Size()
	s.NoError(err, "unexpected error retrieving size")
	size2, err := osFile.Size()
	s.NoError(err, "unexpected error retrieving size")
	s.Equal(size1, size2)
}
TestCopyToFileOS tests "CopyToFile()" between one file in the in-memory FileSystem and the other in the os FileSystem
package mem
import (
	"io"
	"io/ioutil"
	"log"
	"os"
	"path"
	"path/filepath"
	"testing"
	"time"
	"github.com/stretchr/testify/suite"
	"github.com/c2fo/vfs/v6"
	"github.com/c2fo/vfs/v6/backend"
	_os "github.com/c2fo/vfs/v6/backend/os"
)
type memFileTest struct {
	suite.Suite
	testFile   *File
	fileSystem *FileSystem
}
func (s *memFileTest) SetupTest() {
	fs := NewFileSystem()
	file, nerr := fs.NewFile("C", "/test_files/test.txt")
	s.NoError(nerr, "unexpected error creating file")
	s.testFile = file.(*File)
	s.fileSystem = fs
	s.NoError(s.testFile.Touch(), "unexpected error touching file")
}
func (s *memFileTest) TeardownTest() {
	err := s.testFile.Close()
	s.NoError(err, "close error not expected")
	s.NoError(s.testFile.Delete(), "delete failed unexpectedly")
}
func (s *memFileTest) TestZBR() {
	byteSlice := make([]byte, 0)
	_, err := s.testFile.Read(byteSlice)
	s.NoError(err, "read of 0 bytes failed")
}
func (s *memFileTest) TestRARO() {
	sliceToWrite := "hello world!"
	byteSlice := make([]byte, len(sliceToWrite))
	byteSlice2 := make([]byte, len(sliceToWrite))
	_, err := s.testFile.Write([]byte(sliceToWrite))  
	s.NoError(err, "unexpected write error")
	s.NoError(s.testFile.Close(), "unexpected error closing file")  
	_, err = s.testFile.Read(byteSlice)  
	s.NoError(err, "unexpected read error")
	_, err = s.testFile.Read(byteSlice2)
	s.Error(err, "read was expected to fail")
}
func (s *memFileTest) TestRARC() {
	sliceToWrite := "hello world!"
	byteSlice := make([]byte, len(sliceToWrite))
	byteSlice2 := make([]byte, len(sliceToWrite))
	_, err := s.testFile.Write([]byte(sliceToWrite))  
	s.NoError(err, "unexpected write error")
	s.NoError(s.testFile.Close(), "unexpected error closing file")  
	_, err = s.testFile.Read(byteSlice)
	s.NoError(err, "unexpected read error")
	s.NoError(s.testFile.Close(), "unexpected error closing file")
	_, err = s.testFile.Read(byteSlice2)
	s.NoError(err, "unexpected read error")
	s.NoError(err, "read after read failed!")
	s.Equal(byteSlice, byteSlice2)
}
func (s *memFileTest) TestNewFileSameName() {
	sharedPath := "/path/to/file.txt"
	firstFile, err := s.fileSystem.NewFile("", sharedPath)
	s.NoError(err, "unexpected error creating a file")
	expectedText := "hey y'all!"
	_, err = firstFile.Write([]byte(expectedText))
	s.NoError(err, "unexpected error writing to file")
	secondFile, err := s.fileSystem.NewFile("", sharedPath)
	s.NoError(err, "unexpected error creating a file")
	expectedSlice := make([]byte, len(expectedText))
	_, err = secondFile.Read(expectedSlice)
	s.Error(err, "expected read error since firstFile was never closed")
	s.NoError(firstFile.Close(), "unexpected error closing file")
	_, err = secondFile.Read(expectedSlice)
	s.NoError(err, "unexpected read error")
	s.Equal(expectedText, string(expectedSlice))
}
func (s *memFileTest) TestDelete() {
	newFile, err := s.fileSystem.NewFile("", "/home/bar.txt")
	s.NoError(err, "unexpected creation error")
	s.NoError(newFile.Touch(), "unexpected error touching file")
	otherFile, err := s.fileSystem.NewFile("", "/foo.txt")
	s.NoError(err, "unexpected creation error")
	s.NoError(otherFile.Touch(), "unexpected error touching file")
	existence, err := otherFile.Exists()
	s.True(existence)
	s.NoError(err, "unexpected existence error")
	s.NoError(otherFile.Delete(), "Delete unexpectedly failed")
	existence1, err := otherFile.Exists()
	s.False(existence1)
	s.NoError(err, "unexpected existence error")
}
func (s *memFileTest) TestExists1() {
	doesExist, err := s.testFile.Exists()
	s.NoError(err, "unexpected existence error")
	s.True(doesExist)  
	otherFile, err := s.fileSystem.NewFile("", "/foo.txt")
	s.NoError(err, "unexpected error creating file")
	s.NoError(otherFile.Touch(), "unexpected error touching file")
	doesExist1, err := otherFile.Exists()
	s.NoError(err, "unexpected existence error")
	s.True(doesExist1)
}
func (s *memFileTest) TestExists2() {
	otherFile, err := s.fileSystem.NewFile("", "/test_file/foo.txt")
	s.NoError(err, "unexpected error creating file")
	s.NoError(otherFile.Touch(), "unexpected error touching file")
	s.NoError(otherFile.Delete(), "delete unexpectedly failed")
	existence, err := otherFile.Exists()
	s.NoError(err, "unexpected existence error")
	s.False(existence)
}
func (s *memFileTest) TestNewFile() {
	file, err := s.fileSystem.NewFile("", "/test_file/foo.txt")
	s.NoError(err, "unexpected error creating file")
	s.NoError(file.Touch(), "unexpected error touching file")
	filePath := file.Path()
	returnedFile, err := s.fileSystem.NewFile(file.Location().Volume(), filePath)  
	s.NoError(err, "unexpected error retrieving file")
	s.True(returnedFile.Name() == "foo.txt")  
}
func (s *memFileTest) TestSeek2() {
	newFile, err := s.fileSystem.NewFile("", "/home/test_files/subdir/seekTest.txt")
	s.NoError(err, "unexpected error creating a new file")
	initText := "Hello world!"
	_, err = newFile.Write([]byte(initText))
	s.NoError(err, "unexpected write error")
	_, err = newFile.Seek(1, 1)
	s.Error(err, "expected seek to throw an error")
	_, err = newFile.Read(make([]byte, 1))
	s.Error(err, "expected read error")
	s.NoError(newFile.Close(), "unexpected close error")
	_, err = newFile.Seek(0, 0)
	s.NoError(err, "unexpected seek error")
	testByte := make([]byte, 1)
	num, err := newFile.Read(testByte)
	s.NoError(err, "unexpected read error")
	s.True(string(testByte) == "H")
	s.Equal(1, num)
	_, err = newFile.Seek(-2, 1)
	s.Error(err, "seek error expected for seeking into negative bounds")
	_, err = newFile.Seek(1, 1)
	s.NoError(err, "unexpected seek error")
}
func (s *memFileTest) TestNameToURI() {
	name := "/test_files/examples/foo.txt"
	file, err := s.fileSystem.NewFile("C", name)
	s.NoError(err, "unexpected error creating file")
	s.NoError(file.Touch(), "unexpected error touching file")
	returnedFile, err := s.fileSystem.NewFile("C", "/test_files/examples/foo.txt")
	s.NoError(err, "unexpected error retrieving file")
	s.NoError(returnedFile.Touch(), "unexpected error touching file")
	existence, err := returnedFile.Exists()
	s.NoError(err, "unexpected existence error")
	s.True(existence)
	s.Equal("mem://C/test_files/examples/", returnedFile.Location().URI())
	s.Equal("mem://C/test_files/examples/foo.txt", returnedFile.URI())
}
func (s *memFileTest) TestOpenFile() {
	expectedText := "hello world"
	_, err := s.testFile.Write([]byte(expectedText))
	data := make([]byte, len(expectedText))
	s.NoError(err, "write error not expected")
	_, err = s.testFile.Read(data)
	s.Error(err, "read error expected")
	s.False(expectedText == string(data))
}
func (s *memFileTest) TestSeek() {
	expectedText := "new file"
	data := make([]byte, len(expectedText))
	file, err := s.fileSystem.NewFile("", "/test_files/new.txt")
	s.NoError(err, "unexpected error creating a file")
	_, err = file.Write([]byte(expectedText))
	s.NoError(err, "write error not expected")
	_, err = file.Seek(0, 0)
	s.NoError(err, "seek error not expected")
	s.NoError(file.Close(), "unexpected close error")
	_, err = file.Read(data)
	s.NoError(err, "read error not expected")
	s.NoError(file.Close(), "close error not expected")
	s.Equal(expectedText, string(data))
	found, err := file.Exists()
	s.NoError(err, "exists error not expected")
	s.True(found)
	s.NoError(file.Delete(), "file was not deleted properly")
	found2, err := file.Exists()
	s.NoError(err, "exists error not expected")
	s.False(found2)
}
func (s *memFileTest) TestCopyToLocation() {
	newFile, err := s.fileSystem.NewFile("", "/home/foo.txt")
	s.NoError(err, "unexpected error creating file")
	expectedText := "hello world!"
	_, err = s.testFile.Write([]byte(expectedText))
	s.NoError(err, "unexpected write error")
	s.NoError(s.testFile.Close(), "unexpected close error")
	readSlice1 := make([]byte, len(expectedText))
	readSlice2 := make([]byte, len(expectedText))
	copiedFile, cerr := s.testFile.CopyToLocation(newFile.Location())
	s.NoError(cerr, "CopyToLocation unexpectedly failed")
	s.NoError(copiedFile.Touch(), "unexpected error touching file")
	s.True(copiedFile != nil)
	s.EqualValues("/home/test.txt", copiedFile.Path())
	_, err = copiedFile.Read(readSlice1)
	s.NoError(err, "unexpected read error")
	_, err = s.testFile.Read(readSlice2)
	s.NoError(err, "unexpected read error")
	s.EqualValues(string(readSlice2), string(readSlice1))
}
func (s *memFileTest) TestCopyToLocationOW() {
	newFile, err := s.fileSystem.NewFile("C", "/home/test.txt")
	s.NoError(err, "unexpected error creating a file")
	s.NoError(newFile.Touch(), "unexpected error touching file")
	originalText := "goodbye world!"
	_, err = newFile.Write([]byte(originalText))
	s.NoError(err, "unexpected write error")
	s.NoError(newFile.Close(), "unexpected Close error")
	expectedText := "hello world!"
	_, err = s.testFile.Write([]byte(expectedText))
	s.NoError(err, "unexpected write error")
	s.NoError(s.testFile.Close(), "unexpected Close error")
	readSlice := make([]byte, len(expectedText))
	copiedFile, err := s.testFile.CopyToLocation(newFile.Location())
	s.NoError(err, "CopyToLocation unexpectedly failed")
	s.True(copiedFile != nil)
	s.NoError(copiedFile.Close(), "unexpected close error")
	s.EqualValues("/home/test.txt", copiedFile.Path())
	_, err = copiedFile.Read(readSlice)
	s.NoError(err, "unexpected read error")
	s.EqualValues("hello world!", string(readSlice))
}
func (s *memFileTest) TestCopyToNilFile() {
	newFile, err := s.fileSystem.NewFile("", "nilFile.txt")
	s.Error(err, "expected error creating file (bad path)")
	err = s.testFile.CopyToFile(newFile)
	s.Error(err, "expected error for copying to nil file")
}
func (s *memFileTest) TestCopyToLocationOS() {
	expectedText := "hello world!"
	_, err := s.testFile.Write([]byte(expectedText))
	s.NoError(err, "unexpected write error")
	s.NoError(s.testFile.Close(), "unexpected error closing file")
	var osFile vfs.File
	dir, err := ioutil.TempDir("", "osDir")
	if err != nil {
		log.Fatal(err)
	}
	osFileName := filepath.Join(dir, "osFile.txt")
	osFile, err = backend.Backend(_os.Scheme).NewFile("", osFileName)
	s.NoError(err, "unexpected error creating osFile")
	_, err = osFile.Write(make([]byte, 0))
	s.NoError(err, "unexpected error writing zero bytes to osFile")
	exists, err := osFile.Exists()
	s.NoError(err, "unexpected existence error")
	s.True(exists)
	readSlice := make([]byte, len(expectedText))
	readSlice2 := make([]byte, len(expectedText))
	copiedFile, err := s.testFile.CopyToLocation(osFile.Location())
	s.NoError(err, "CopyToLocation unexpectedly failed")
	s.NoError(copiedFile.Close(), "unexpected Close error")
	s.True(copiedFile != nil)
	s.EqualValues("/test_files/test.txt", s.testFile.Path())          
	s.EqualValues(filepath.Join(dir, "test.txt"), copiedFile.Path())  
	_, err = copiedFile.Read(readSlice)
	s.NoError(err, "unexpected read error")
	_, err = s.testFile.Read(readSlice2)
	s.NoError(err, "unexpected read error")
	s.EqualValues(string(readSlice2), string(readSlice))  
	cleanErr := os.RemoveAll(dir)                         
	s.NoError(cleanErr, "unexpected error cleaning up osFiles")
}
func (s *memFileTest) TestCopyToFile() {
	expectedText := "hello world"
	otherFile, err := s.fileSystem.NewFile("", "/test.txt")
	s.NoError(err, "unexpected error creating file")
	readSlice1 := make([]byte, len(expectedText))
	readSlice2 := make([]byte, len(expectedText))
	num, err := s.testFile.Write([]byte(expectedText))
	s.False(num == 0)
	s.NoError(err, "no error expected from Write but got one")
	s.NoError(s.testFile.Close(), "unexpected error closing a file")
	s.NoError(otherFile.Touch(), "unexpected error touching file")
	err = s.testFile.CopyToFile(otherFile)
	s.NoError(err, "copy to file failed unexpectedly")
	_, err = s.testFile.Read(readSlice1)
	s.NoError(err, "unexpected read error")
	otherFile, err = s.fileSystem.NewFile("", "/test.txt")
	s.NoError(err, "unexpected creation error")
	_, err = otherFile.Read(readSlice2)
	s.NoError(err, "unexpected read error")
	s.EqualValues(string(readSlice1), string(readSlice2))
}