createFile writes the content to a temporary file, returning the path. Good for testing config files.
(t *testing.T, content string)
| 27 | // createFile writes the content to a temporary file, returning the path. |
| 28 | // Good for testing config files. |
| 29 | func createFile(t *testing.T, content string) (path string) { |
| 30 | t.Helper() |
| 31 | |
| 32 | f, err := os.CreateTemp(t.TempDir(), "config-*.yaml") |
| 33 | if err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | |
| 37 | t.Cleanup(func() { _ = os.Remove(f.Name()) }) |
| 38 | |
| 39 | n, err := f.WriteString(content) |
| 40 | if err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | if n != len(content) { |
| 44 | t.Fatal("failed to write the complete content") |
| 45 | } |
| 46 | |
| 47 | return f.Name() |
| 48 | } |
| 49 | |
| 50 | // createFileF writes the content format string with the applied args to a |
| 51 | // temporary file, returning the path. Good for testing config files. |
no test coverage detected