Skip to content

Commit ead86d4

Browse files
committed
lint: fix usetesting issues
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
1 parent 1b223d6 commit ead86d4

File tree

2 files changed

+21
-43
lines changed

2 files changed

+21
-43
lines changed

fileutils/path_test.go

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,39 @@ import (
2525
"github.com/stretchr/testify/require"
2626
)
2727

28-
func makeDirStructure(tgt string) (string, string, error) {
28+
func makeDirStructure(tb testing.TB, tgt string) (string, string) {
29+
tb.Helper()
30+
2931
if tgt == "" {
3032
tgt = "pkgpaths"
3133
}
32-
td, err := os.MkdirTemp("", tgt)
33-
if err != nil {
34-
return "", "", err
35-
}
36-
td2, err := os.MkdirTemp("", tgt+"-2")
37-
if err != nil {
38-
return "", "", err
39-
}
34+
35+
td := tb.TempDir()
4036
realPath := filepath.Join(td, "src", "foo", "bar")
41-
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
42-
return "", "", err
43-
}
37+
err := os.MkdirAll(realPath, os.ModePerm)
38+
require.NoError(tb, err)
4439
linkPathBase := filepath.Join(td, "src", "baz")
45-
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
46-
return "", "", err
47-
}
40+
err = os.MkdirAll(linkPathBase, os.ModePerm)
41+
require.NoError(tb, err)
4842
linkPath := filepath.Join(linkPathBase, "das")
49-
if err := os.Symlink(realPath, linkPath); err != nil {
50-
return "", "", err
51-
}
43+
err = os.Symlink(realPath, linkPath)
44+
require.NoError(tb, err)
5245

46+
td2 := tb.TempDir()
5347
realPath = filepath.Join(td2, "src", "fuu", "bir")
54-
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
55-
return "", "", err
56-
}
48+
err = os.MkdirAll(realPath, os.ModePerm)
49+
require.NoError(tb, err)
5750
linkPathBase = filepath.Join(td2, "src", "biz")
58-
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
59-
return "", "", err
60-
}
51+
err = os.MkdirAll(linkPathBase, os.ModePerm)
52+
require.NoError(tb, err)
6153
linkPath = filepath.Join(linkPathBase, "dis")
62-
if err := os.Symlink(realPath, linkPath); err != nil {
63-
return "", "", err
64-
}
65-
return td, td2, nil
54+
err = os.Symlink(realPath, linkPath)
55+
require.NoError(tb, err)
56+
return td, td2
6657
}
6758

6859
func TestFindPackage(t *testing.T) {
69-
pth, pth2, err := makeDirStructure("")
70-
if err != nil {
71-
t.Fatal(err)
72-
}
73-
defer func() {
74-
os.RemoveAll(pth)
75-
os.RemoveAll(pth2)
76-
}()
60+
pth, pth2 := makeDirStructure(t, "")
7761

7862
searchPath := pth + string(filepath.ListSeparator) + pth2
7963
// finds package when real name mentioned

fileutils_iface_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ import (
2626
func TestFileUtilsIface(t *testing.T) {
2727
t.Run("deprecated functions should work", func(t *testing.T) {
2828
t.Run("with test package path", func(t *testing.T) {
29-
const tgt = "testpath"
30-
31-
td, err := os.MkdirTemp("", tgt) //nolint:usetesting // as t.TempDir in testing not yet fully working (on windows)
32-
require.NoError(t, err)
33-
t.Cleanup(func() {
34-
_ = os.RemoveAll(td)
35-
})
29+
td := t.TempDir()
3630

3731
realPath := filepath.Join(td, "src", "foo", "bar")
3832
require.NoError(t, os.MkdirAll(realPath, os.ModePerm))

0 commit comments

Comments
 (0)