github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/helpers/file.go (about) 1 package helpers 2 3 import ( 4 "io/ioutil" 5 "strings" 6 7 . "github.com/onsi/gomega" 8 ) 9 10 // ConvertPathToRegularExpression converts a windows file path into a 11 // string which may be embedded in a ginkgo-compatible regular expression. 12 func ConvertPathToRegularExpression(path string) string { 13 return strings.Replace(path, "\\", "\\\\", -1) 14 } 15 16 // TempFileWithContent writes a temp file with given content and return the 17 // file name. 18 func TempFileWithContent(contents string) string { 19 tempFile, err := ioutil.TempFile("", "*") 20 Expect(err).NotTo(HaveOccurred()) 21 defer tempFile.Close() 22 23 bytes := []byte(contents) 24 _, err = tempFile.Write(bytes) 25 Expect(err).NotTo(HaveOccurred()) 26 27 return tempFile.Name() 28 }