MCPcopy Index your code
hub / github.com/coder/coder / CreateTemp

Function CreateTemp

testutil/temp.go:38–54  ·  view source on GitHub ↗

CreateTemp is a convenience function for creating a temporary file, like os.CreateTemp, but it also registers a cleanup function to close and remove the file.

(t *testing.T, dir, pattern string)

Source from the content-addressed store, hash-verified

36// os.CreateTemp, but it also registers a cleanup function to close and remove
37// the file.
38func CreateTemp(t *testing.T, dir, pattern string) *os.File {
39 t.Helper()
40
41 if dir == "" {
42 dir = t.TempDir()
43 }
44 f, err := os.CreateTemp(dir, pattern)
45 require.NoError(t, err, "create temp file")
46 t.Cleanup(func() {
47 _ = f.Close()
48 err = os.Remove(f.Name())
49 if err != nil {
50 t.Logf("CreateTemp: Cleanup: remove failed for %q: %v", f.Name(), err)
51 }
52 })
53 return f
54}
55
56// TempDirResolved returns t.TempDir() with symlinks resolved via
57// filepath.EvalSymlinks. Tests that compare paths against values

Callers 1

TestReinitializeAgentFunction · 0.92

Calls 7

HelperMethod · 0.65
TempDirMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
LogfMethod · 0.65

Tested by 1

TestReinitializeAgentFunction · 0.74