github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+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 func TempFileWithContent(contents string) string { 17 tempFile, err := ioutil.TempFile("", "*") 18 Expect(err).NotTo(HaveOccurred()) 19 defer tempFile.Close() 20 21 bytes := []byte(contents) 22 _, err = tempFile.Write(bytes) 23 Expect(err).NotTo(HaveOccurred()) 24 25 return tempFile.Name() 26 }