github.com/bilus/oya@v0.0.3-0.20190301162104-da4acbd394c6/testutil/helpers.go (about) 1 package testutil 2 3 import ( 4 "io" 5 "os" 6 "testing" 7 ) 8 9 func CopyFile(fromPath, toPath string) error { 10 from, err := os.Open(fromPath) 11 if err != nil { 12 return err 13 } 14 defer from.Close() 15 16 to, err := os.OpenFile(toPath, os.O_RDWR|os.O_CREATE, 0666) 17 if err != nil { 18 return err 19 } 20 defer to.Close() 21 22 _, err = io.Copy(to, from) 23 return err 24 } 25 26 func MustCopyFile(t *testing.T, fromPath, toPath string) { 27 err := CopyFile(fromPath, toPath) 28 AssertNoErr(t, err, "Error copying file from %v to %v", fromPath, toPath) 29 }