Standard library / testing
testing.T.TempDir()
Create an isolated temporary directory and register its removal when the test and subtests finish. Expected stdout: 'true\nPASS\n'. Run as a _test.go file using the Go test harness.
Formal Syntax & Structure
go syntaxgo
func (c *T) TempDir() stringReturn Value
string
Result of the operation described above.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "testing")
func TestReference(t *testing.T) { d := t.TempDir() info, err := os.Stat(d) fmt.Println(err == nil && info.IsDir())}