Skip to content

lint: fix usetesting issues #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions fileutils/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,39 @@ import (
"github.com/stretchr/testify/require"
)

func makeDirStructure(tgt string) (string, string, error) {
func makeDirStructure(tb testing.TB, tgt string) (string, string) {
tb.Helper()

if tgt == "" {
tgt = "pkgpaths"
}
td, err := os.MkdirTemp("", tgt)
if err != nil {
return "", "", err
}
td2, err := os.MkdirTemp("", tgt+"-2")
if err != nil {
return "", "", err
}

td := tb.TempDir()
realPath := filepath.Join(td, "src", "foo", "bar")
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
return "", "", err
}
err := os.MkdirAll(realPath, os.ModePerm)
require.NoError(tb, err)
linkPathBase := filepath.Join(td, "src", "baz")
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
return "", "", err
}
err = os.MkdirAll(linkPathBase, os.ModePerm)
require.NoError(tb, err)
linkPath := filepath.Join(linkPathBase, "das")
if err := os.Symlink(realPath, linkPath); err != nil {
return "", "", err
}
err = os.Symlink(realPath, linkPath)
require.NoError(tb, err)

td2 := tb.TempDir()
realPath = filepath.Join(td2, "src", "fuu", "bir")
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
return "", "", err
}
err = os.MkdirAll(realPath, os.ModePerm)
require.NoError(tb, err)
linkPathBase = filepath.Join(td2, "src", "biz")
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
return "", "", err
}
err = os.MkdirAll(linkPathBase, os.ModePerm)
require.NoError(tb, err)
linkPath = filepath.Join(linkPathBase, "dis")
if err := os.Symlink(realPath, linkPath); err != nil {
return "", "", err
}
return td, td2, nil
err = os.Symlink(realPath, linkPath)
require.NoError(tb, err)
return td, td2
}

func TestFindPackage(t *testing.T) {
pth, pth2, err := makeDirStructure("")
if err != nil {
t.Fatal(err)
}
defer func() {
os.RemoveAll(pth)
os.RemoveAll(pth2)
}()
pth, pth2 := makeDirStructure(t, "")

searchPath := pth + string(filepath.ListSeparator) + pth2
// finds package when real name mentioned
Expand Down
8 changes: 1 addition & 7 deletions fileutils_iface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ import (
func TestFileUtilsIface(t *testing.T) {
t.Run("deprecated functions should work", func(t *testing.T) {
t.Run("with test package path", func(t *testing.T) {
const tgt = "testpath"

td, err := os.MkdirTemp("", tgt) //nolint:usetesting // as t.TempDir in testing not yet fully working (on windows)
require.NoError(t, err)
t.Cleanup(func() {
_ = os.RemoveAll(td)
})
td := t.TempDir()

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