Skip to content

Commit

Permalink
cleanup: use built-in t.TempDir() (#6471)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <nick.santos@docker.com>
  • Loading branch information
nicks authored Nov 19, 2024
1 parent ea06944 commit 060546c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 181 deletions.
9 changes: 2 additions & 7 deletions internal/controllers/core/extensionrepo/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
"k8s.io/apimachinery/pkg/types"

"github.com/tilt-dev/tilt/internal/controllers/fake"
"github.com/tilt-dev/tilt/internal/testutils/tempdir"
"github.com/tilt-dev/tilt/internal/xdg"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/wmclient/pkg/os/temp"
)

func TestInvalidRepo(t *testing.T) {
Expand Down Expand Up @@ -208,11 +206,8 @@ type fixture struct {

func newFixture(t *testing.T) *fixture {
cfb := fake.NewControllerFixtureBuilder(t)
tmpDir, err := temp.NewDir(tempdir.SanitizeFileName(t.Name()))
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(tmpDir.Path()) })

base := xdg.FakeBase{Dir: tmpDir.Path()}
tmpDir := t.TempDir()
base := xdg.FakeBase{Dir: tmpDir}
r, err := NewReconciler(cfb.Client, cfb.Store, base)
require.NoError(t, err)

Expand Down
7 changes: 6 additions & 1 deletion internal/filelock/with_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ func withLock(filename string, lt lockType, action func() error) error {
if err != nil {
return err
}
defer func() {
_ = lockfile.Close()
}()
err = lock(lockfile, lt)
if err != nil {
return err
}
defer func() { _ = Unlock(lockfile) }()
defer func() {
_ = Unlock(lockfile)
}()
return action()
}
36 changes: 8 additions & 28 deletions internal/testutils/tempdir/temp_dir_fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"

"github.com/tilt-dev/wmclient/pkg/os/temp"
)

type TempDirFixture struct {
t testing.TB
dir *temp.TempDir
dir string
oldDir string
}

Expand All @@ -25,27 +22,20 @@ func SanitizeFileName(name string) string {
}

func NewTempDirFixture(t testing.TB) *TempDirFixture {
dir, err := temp.NewDir(SanitizeFileName(t.Name()))
if err != nil {
t.Fatalf("Error making temp dir: %v", err)
}

ret := &TempDirFixture{
f := &TempDirFixture{
t: t,
dir: dir,
dir: t.TempDir(),
}

t.Cleanup(ret.tearDown)

return ret
t.Cleanup(f.tearDown)
return f
}

func (f *TempDirFixture) T() testing.TB {
return f.t
}

func (f *TempDirFixture) Path() string {
return f.dir.Path()
return f.dir
}

func (f *TempDirFixture) Chdir() {
Expand Down Expand Up @@ -154,11 +144,11 @@ func (f *TempDirFixture) Rm(pathInRepo string) {
}

func (f *TempDirFixture) NewFile(prefix string) (*os.File, error) {
return os.CreateTemp(f.dir.Path(), prefix)
return os.CreateTemp(f.dir, prefix)
}

func (f *TempDirFixture) TempDir(prefix string) string {
name, err := os.MkdirTemp(f.dir.Path(), prefix)
name, err := os.MkdirTemp(f.dir, prefix)
if err != nil {
f.t.Fatal(err)
}
Expand All @@ -172,14 +162,4 @@ func (f *TempDirFixture) tearDown() {
f.t.Fatal(err)
}
}

err := f.dir.TearDown()
if err != nil && runtime.GOOS == "windows" &&
(strings.Contains(err.Error(), "The process cannot access the file") ||
strings.Contains(err.Error(), "Access is denied")) {
// NOTE(nick): I'm not convinced that this is a real problem.
// I think it might just be clean up of file notification I/O.
} else if err != nil {
f.t.Fatal(err)
}
}
9 changes: 0 additions & 9 deletions vendor/github.com/tilt-dev/wmclient/pkg/env/debug.go

This file was deleted.

15 changes: 0 additions & 15 deletions vendor/github.com/tilt-dev/wmclient/pkg/os/temp/dir.go

This file was deleted.

40 changes: 0 additions & 40 deletions vendor/github.com/tilt-dev/wmclient/pkg/os/temp/persistent.go

This file was deleted.

79 changes: 0 additions & 79 deletions vendor/github.com/tilt-dev/wmclient/pkg/os/temp/temp.go

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,6 @@ github.com/tilt-dev/tilt-apiserver/pkg/storage/filepath
## explicit; go 1.13
github.com/tilt-dev/wmclient/pkg/analytics
github.com/tilt-dev/wmclient/pkg/dirs
github.com/tilt-dev/wmclient/pkg/env
github.com/tilt-dev/wmclient/pkg/os/temp
# github.com/tonistiigi/fsutil v0.0.0-20240424095704-91a3fc46842c
## explicit; go 1.20
github.com/tonistiigi/fsutil
Expand Down

0 comments on commit 060546c

Please sign in to comment.