github.com/lheiskan/zebrapack@v4.1.1-0.20181107023619-e955d028f9bf+incompatible/cmd/addzid/old_bambam_tests/cpfile_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "testing" 8 9 cv "github.com/glycerine/goconvey/convey" 10 ) 11 12 func TestCpCopiesFilesIntoDirHier(t *testing.T) { 13 14 cv.Convey("Cp() function should create directories in destinationPath if need be", t, func() { 15 16 origdir, tmpdir := MakeAndMoveToTempDir() 17 defer TempDirCleanup(origdir, tmpdir) 18 hier := fmt.Sprintf("a%cb%cc%c", os.PathSeparator, os.PathSeparator, os.PathSeparator) 19 goal := hier + "cpfile.go" 20 err := Cp(origdir+string(os.PathSeparator)+"cpfile.go", tmpdir+string(os.PathSeparator)+hier) 21 cv.So(err, cv.ShouldEqual, nil) 22 cv.So(FileExists(goal), cv.ShouldEqual, true) 23 }) 24 } 25 26 func MakeAndMoveToTempDir() (origdir string, tmpdir string) { 27 28 var err error 29 origdir, err = os.Getwd() 30 if err != nil { 31 panic(err) 32 } 33 tmpdir, err = ioutil.TempDir(origdir, "temptestdir") 34 if err != nil { 35 panic(err) 36 } 37 err = os.Chdir(tmpdir) 38 if err != nil { 39 panic(err) 40 } 41 42 return origdir, tmpdir 43 } 44 45 func TempDirCleanup(origdir string, tmpdir string) { 46 // cleanup 47 os.Chdir(origdir) 48 err := os.RemoveAll(tmpdir) 49 if err != nil { 50 panic(err) 51 } 52 }