mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-08 09:07:44 +00:00
all: use testing.T.TempDir
Bit of Friday cleanup. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
ed5d5f920f
commit
585a0d8997
@ -7,8 +7,6 @@
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -25,11 +23,7 @@ func TestRunMultipleAccepts(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
td, err := ioutil.TempDir("", "TestRunMultipleAccepts")
|
td := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(td)
|
|
||||||
socketPath := filepath.Join(td, "tailscale.sock")
|
socketPath := filepath.Join(td, "tailscale.sock")
|
||||||
|
|
||||||
logf := func(format string, args ...interface{}) {
|
logf := func(format string, args ...interface{}) {
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"unicode"
|
"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) {
|
func TestQueue(t *testing.T) {
|
||||||
td, filePrefix := genFilePrefix(t)
|
filePrefix := t.TempDir()
|
||||||
defer os.RemoveAll(td)
|
|
||||||
|
|
||||||
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
||||||
|
|
||||||
f.readEOF(t)
|
f.readEOF(t)
|
||||||
@ -90,8 +78,7 @@ func TestQueue(t *testing.T) {
|
|||||||
|
|
||||||
func TestRecover(t *testing.T) {
|
func TestRecover(t *testing.T) {
|
||||||
t.Run("empty", func(t *testing.T) {
|
t.Run("empty", func(t *testing.T) {
|
||||||
td, filePrefix := genFilePrefix(t)
|
filePrefix := t.TempDir()
|
||||||
defer os.RemoveAll(td)
|
|
||||||
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
||||||
f.write(t, "hello")
|
f.write(t, "hello")
|
||||||
f.read(t, "hello")
|
f.read(t, "hello")
|
||||||
@ -104,8 +91,7 @@ func TestRecover(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("cur", func(t *testing.T) {
|
t.Run("cur", func(t *testing.T) {
|
||||||
td, filePrefix := genFilePrefix(t)
|
filePrefix := t.TempDir()
|
||||||
defer os.RemoveAll(td)
|
|
||||||
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
||||||
f.write(t, "hello")
|
f.write(t, "hello")
|
||||||
f.close(t)
|
f.close(t)
|
||||||
@ -123,8 +109,7 @@ func TestRecover(t *testing.T) {
|
|||||||
filch_test.go:129: r.ReadLine()="hello", want "world"
|
filch_test.go:129: r.ReadLine()="hello", want "world"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
td, filePrefix := genFilePrefix(t)
|
filePrefix := t.TempDir()
|
||||||
defer os.RemoveAll(td)
|
|
||||||
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
||||||
f.write(t, "hello")
|
f.write(t, "hello")
|
||||||
f.read(t, "hello")
|
f.read(t, "hello")
|
||||||
@ -155,8 +140,7 @@ func TestFilchStderr(t *testing.T) {
|
|||||||
stderrFD = 2
|
stderrFD = 2
|
||||||
}()
|
}()
|
||||||
|
|
||||||
td, filePrefix := genFilePrefix(t)
|
filePrefix := t.TempDir()
|
||||||
defer os.RemoveAll(td)
|
|
||||||
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: true})
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: true})
|
||||||
f.write(t, "hello")
|
f.write(t, "hello")
|
||||||
if _, err := fmt.Fprintf(pipeW, "filch\n"); err != nil {
|
if _, err := fmt.Fprintf(pipeW, "filch\n"); err != nil {
|
||||||
|
@ -7,17 +7,12 @@
|
|||||||
package exec
|
package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookPathUnixEmptyPath(t *testing.T) {
|
func TestLookPathUnixEmptyPath(t *testing.T) {
|
||||||
tmp, err := ioutil.TempDir("", "TestLookPathUnixEmptyPath")
|
tmp := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal("TempDir failed: ", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmp)
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Getwd failed: ", err)
|
t.Fatal("Getwd failed: ", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user