From 585a0d8997bde7f9034979807162505c025c02c1 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 2 Oct 2020 15:42:56 -0700 Subject: [PATCH] all: use testing.T.TempDir Bit of Friday cleanup. Signed-off-by: Josh Bleecher Snyder --- ipn/ipnserver/server_test.go | 8 +------- logtail/filch/filch_test.go | 26 +++++--------------------- tempfork/osexec/lp_unix_test.go | 7 +------ 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/ipn/ipnserver/server_test.go b/ipn/ipnserver/server_test.go index 523c91836..9a368c17f 100644 --- a/ipn/ipnserver/server_test.go +++ b/ipn/ipnserver/server_test.go @@ -7,8 +7,6 @@ package ipnserver_test import ( "context" "fmt" - "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -25,11 +23,7 @@ func TestRunMultipleAccepts(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - td, err := ioutil.TempDir("", "TestRunMultipleAccepts") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(td) + td := t.TempDir() socketPath := filepath.Join(td, "tailscale.sock") logf := func(format string, args ...interface{}) { diff --git a/logtail/filch/filch_test.go b/logtail/filch/filch_test.go index b9fe27ebb..887b629ee 100644 --- a/logtail/filch/filch_test.go +++ b/logtail/filch/filch_test.go @@ -8,7 +8,6 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" "strings" "testing" "unicode" @@ -56,19 +55,8 @@ func (f *filchTest) close(t *testing.T) { } } -func genFilePrefix(t *testing.T) (dir, prefix string) { - t.Helper() - dir, err := ioutil.TempDir("", "filch") - if err != nil { - t.Fatal(err) - } - return dir, filepath.Join(dir, "ringbuffer-") -} - func TestQueue(t *testing.T) { - td, filePrefix := genFilePrefix(t) - defer os.RemoveAll(td) - + filePrefix := t.TempDir() f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false}) f.readEOF(t) @@ -90,8 +78,7 @@ func TestQueue(t *testing.T) { func TestRecover(t *testing.T) { t.Run("empty", func(t *testing.T) { - td, filePrefix := genFilePrefix(t) - defer os.RemoveAll(td) + filePrefix := t.TempDir() f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false}) f.write(t, "hello") f.read(t, "hello") @@ -104,8 +91,7 @@ func TestRecover(t *testing.T) { }) t.Run("cur", func(t *testing.T) { - td, filePrefix := genFilePrefix(t) - defer os.RemoveAll(td) + filePrefix := t.TempDir() f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false}) f.write(t, "hello") f.close(t) @@ -123,8 +109,7 @@ func TestRecover(t *testing.T) { filch_test.go:129: r.ReadLine()="hello", want "world" */ - td, filePrefix := genFilePrefix(t) - defer os.RemoveAll(td) + filePrefix := t.TempDir() f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false}) f.write(t, "hello") f.read(t, "hello") @@ -155,8 +140,7 @@ func TestFilchStderr(t *testing.T) { stderrFD = 2 }() - td, filePrefix := genFilePrefix(t) - defer os.RemoveAll(td) + filePrefix := t.TempDir() f := newFilchTest(t, filePrefix, Options{ReplaceStderr: true}) f.write(t, "hello") if _, err := fmt.Fprintf(pipeW, "filch\n"); err != nil { diff --git a/tempfork/osexec/lp_unix_test.go b/tempfork/osexec/lp_unix_test.go index e4656cafb..5f4a9b44d 100644 --- a/tempfork/osexec/lp_unix_test.go +++ b/tempfork/osexec/lp_unix_test.go @@ -7,17 +7,12 @@ package exec import ( - "io/ioutil" "os" "testing" ) func TestLookPathUnixEmptyPath(t *testing.T) { - tmp, err := ioutil.TempDir("", "TestLookPathUnixEmptyPath") - if err != nil { - t.Fatal("TempDir failed: ", err) - } - defer os.RemoveAll(tmp) + tmp := t.TempDir() wd, err := os.Getwd() if err != nil { t.Fatal("Getwd failed: ", err)