aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_test.go')
-rw-r--r--src/testing/testing_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go
index 45e44683b4..afb35a96d4 100644
--- a/src/testing/testing_test.go
+++ b/src/testing/testing_test.go
@@ -5,6 +5,7 @@
package testing_test
import (
+ "io/ioutil"
"os"
"testing"
)
@@ -16,3 +17,50 @@ import (
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
+
+func TestTempDir(t *testing.T) {
+ dirCh := make(chan string, 1)
+ t.Cleanup(func() {
+ // Verify directory has been removed.
+ select {
+ case dir := <-dirCh:
+ fi, err := os.Stat(dir)
+ if os.IsNotExist(err) {
+ // All good
+ return
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Errorf("directory %q stil exists: %v, isDir=%v", dir, fi, fi.IsDir())
+ default:
+ if !t.Failed() {
+ t.Fatal("never received dir channel")
+ }
+ }
+ })
+
+ dir := t.TempDir()
+ if dir == "" {
+ t.Fatal("expected dir")
+ }
+ dir2 := t.TempDir()
+ if dir != dir2 {
+ t.Fatal("directory changed between calls")
+ }
+ dirCh <- dir
+ fi, err := os.Stat(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !fi.IsDir() {
+ t.Errorf("dir %q is not a dir", dir)
+ }
+ fis, err := ioutil.ReadDir(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(fis) > 0 {
+ t.Errorf("unexpected %d files in TempDir: %v", len(fis), fis)
+ }
+}