Skip to content
Snippets Groups Projects
Commit 5187baeb authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Gopher Robot
Browse files

os: use t.TempDir in TestMkdirTemp, TestCreateTemp

This simplifies tests a little bit.

Change-Id: I910e3c97cfd20b26951d2a4909d86b5be06bde56
Reviewed-on: https://go-review.googlesource.com/c/go/+/606899


LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: default avatarCherry Mui <cherryyz@google.com>
Reviewed-by: default avatarIan Lance Taylor <iant@google.com>
parent ef0b0154
No related branches found
No related tags found
No related merge requests found
...@@ -17,13 +17,7 @@ import ( ...@@ -17,13 +17,7 @@ import (
func TestCreateTemp(t *testing.T) { func TestCreateTemp(t *testing.T) {
t.Parallel() t.Parallel()
dir, err := MkdirTemp("", "TestCreateTempBadDir") nonexistentDir := filepath.Join(t.TempDir(), "_not_exists_")
if err != nil {
t.Fatal(err)
}
defer RemoveAll(dir)
nonexistentDir := filepath.Join(dir, "_not_exists_")
f, err := CreateTemp(nonexistentDir, "foo") f, err := CreateTemp(nonexistentDir, "foo")
if f != nil || err == nil { if f != nil || err == nil {
t.Errorf("CreateTemp(%q, `foo`) = %v, %v", nonexistentDir, f, err) t.Errorf("CreateTemp(%q, `foo`) = %v, %v", nonexistentDir, f, err)
...@@ -57,11 +51,7 @@ func TestCreateTempPattern(t *testing.T) { ...@@ -57,11 +51,7 @@ func TestCreateTempPattern(t *testing.T) {
func TestCreateTempBadPattern(t *testing.T) { func TestCreateTempBadPattern(t *testing.T) {
t.Parallel() t.Parallel()
tmpDir, err := MkdirTemp("", t.Name()) tmpDir := t.TempDir()
if err != nil {
t.Fatal(err)
}
defer RemoveAll(tmpDir)
const sep = string(PathSeparator) const sep = string(PathSeparator)
tests := []struct { tests := []struct {
...@@ -152,14 +142,8 @@ func TestMkdirTemp(t *testing.T) { ...@@ -152,14 +142,8 @@ func TestMkdirTemp(t *testing.T) {
func TestMkdirTempBadDir(t *testing.T) { func TestMkdirTempBadDir(t *testing.T) {
t.Parallel() t.Parallel()
dir, err := MkdirTemp("", "MkdirTempBadDir") badDir := filepath.Join(t.TempDir(), "not-exist")
if err != nil { _, err := MkdirTemp(badDir, "foo")
t.Fatal(err)
}
defer RemoveAll(dir)
badDir := filepath.Join(dir, "not-exist")
_, err = MkdirTemp(badDir, "foo")
if pe, ok := err.(*fs.PathError); !ok || !IsNotExist(err) || pe.Path != badDir { if pe, ok := err.(*fs.PathError); !ok || !IsNotExist(err) || pe.Path != badDir {
t.Errorf("TempDir error = %#v; want PathError for path %q satisfying IsNotExist", err, badDir) t.Errorf("TempDir error = %#v; want PathError for path %q satisfying IsNotExist", err, badDir)
} }
...@@ -168,11 +152,7 @@ func TestMkdirTempBadDir(t *testing.T) { ...@@ -168,11 +152,7 @@ func TestMkdirTempBadDir(t *testing.T) {
func TestMkdirTempBadPattern(t *testing.T) { func TestMkdirTempBadPattern(t *testing.T) {
t.Parallel() t.Parallel()
tmpDir, err := MkdirTemp("", t.Name()) tmpDir := t.TempDir()
if err != nil {
t.Fatal(err)
}
defer RemoveAll(tmpDir)
const sep = string(PathSeparator) const sep = string(PathSeparator)
tests := []struct { tests := []struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment