TempFileWithContent writes a temp file with given content and return the file name.
(contents string)
| 17 | // TempFileWithContent writes a temp file with given content and return the |
| 18 | // file name. |
| 19 | func TempFileWithContent(contents string) string { |
| 20 | tempFile, err := os.CreateTemp("", "*") |
| 21 | Expect(err).NotTo(HaveOccurred()) |
| 22 | defer tempFile.Close() |
| 23 | |
| 24 | bytes := []byte(contents) |
| 25 | _, err = tempFile.Write(bytes) |
| 26 | Expect(err).NotTo(HaveOccurred()) |
| 27 | |
| 28 | return tempFile.Name() |
| 29 | } |
| 30 | |
| 31 | // TempDirAbsolutePath wraps `os.MkdirTemp`, ensuring symlinks are expanded |
| 32 | // before returning the path |
no test coverage detected