diff --git a/.golangci.yml b/.golangci.yml index 2ccb77a5..e3dee875 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,7 @@ linters: - staticcheck - unconvert - unused + - usetesting - wastedassign settings: depguard: diff --git a/act/common/git/git_test.go b/act/common/git/git_test.go index a4e6fb39..640c033f 100644 --- a/act/common/git/git_test.go +++ b/act/common/git/git_test.go @@ -53,13 +53,6 @@ func TestFindGitSlug(t *testing.T) { } } -func testDir(t *testing.T) string { - basedir, err := os.MkdirTemp("", "act-test") - require.NoError(t, err) - t.Cleanup(func() { _ = os.RemoveAll(basedir) }) - return basedir -} - func cleanGitHooks(dir string) error { hooksDir := filepath.Join(dir, ".git", "hooks") files, err := os.ReadDir(hooksDir) @@ -84,7 +77,7 @@ func cleanGitHooks(dir string) error { func TestFindGitRemoteURL(t *testing.T) { assert := assert.New(t) - basedir := testDir(t) + basedir := t.TempDir() gitConfig() err := gitCmd("init", basedir) assert.NoError(err) @@ -108,7 +101,7 @@ func TestFindGitRemoteURL(t *testing.T) { } func TestGitFindRef(t *testing.T) { - basedir := testDir(t) + basedir := t.TempDir() gitConfig() for name, tt := range map[string]struct { @@ -219,7 +212,7 @@ func TestGitCloneExecutor(t *testing.T) { clone := NewGitCloneExecutor(NewGitCloneExecutorInput{ URL: tt.URL, Ref: tt.Ref, - Dir: testDir(t), + Dir: t.TempDir(), }) err := clone(t.Context()) diff --git a/act/container/host_environment_test.go b/act/container/host_environment_test.go index 2301c420..6efb8560 100644 --- a/act/container/host_environment_test.go +++ b/act/container/host_environment_test.go @@ -15,9 +15,7 @@ import ( var _ ExecutionsEnvironment = &HostEnvironment{} func TestCopyDir(t *testing.T) { - dir, err := os.MkdirTemp("", "test-host-env-*") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() ctx := t.Context() e := &HostEnvironment{ Path: filepath.Join(dir, "path"), @@ -31,14 +29,12 @@ func TestCopyDir(t *testing.T) { _ = os.MkdirAll(e.TmpDir, 0o700) _ = os.MkdirAll(e.ToolCache, 0o700) _ = os.MkdirAll(e.ActPath, 0o700) - err = e.CopyDir(e.Workdir, e.Path, true)(ctx) + err := e.CopyDir(e.Workdir, e.Path, true)(ctx) assert.NoError(t, err) } func TestGetContainerArchive(t *testing.T) { - dir, err := os.MkdirTemp("", "test-host-env-*") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() ctx := t.Context() e := &HostEnvironment{ Path: filepath.Join(dir, "path"), @@ -53,7 +49,7 @@ func TestGetContainerArchive(t *testing.T) { _ = os.MkdirAll(e.ToolCache, 0o700) _ = os.MkdirAll(e.ActPath, 0o700) expectedContent := []byte("sdde/7sh") - err = os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0o600) + err := os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0o600) assert.NoError(t, err) archive, err := e.GetContainerArchive(ctx, e.Path) assert.NoError(t, err) diff --git a/act/container/linux_container_environment_extensions_test.go b/act/container/linux_container_environment_extensions_test.go index 38111714..32034874 100644 --- a/act/container/linux_container_environment_extensions_test.go +++ b/act/container/linux_container_environment_extensions_test.go @@ -35,18 +35,13 @@ func TestContainerPath(t *testing.T) { {fmt.Sprintf("/mnt/%v/act", rootDriveLetter), "act", fmt.Sprintf("%s\\", rootDrive)}, } { if v.workDir != "" { - if err := os.Chdir(v.workDir); err != nil { - log.Error(err) - t.Fail() - } + t.Chdir(v.workDir) } assert.Equal(t, v.destinationPath, linuxcontainerext.ToContainerPath(v.sourcePath)) } - if err := os.Chdir(cwd); err != nil { - log.Error(err) - } + t.Chdir(cwd) } else { cwd, err := os.Getwd() if err != nil {