Skip to content

Commit 060546c

Browse files
authored
cleanup: use built-in t.TempDir() (#6471)
Signed-off-by: Nick Santos <[email protected]>
1 parent ea06944 commit 060546c

File tree

8 files changed

+16
-181
lines changed

8 files changed

+16
-181
lines changed

internal/controllers/core/extensionrepo/reconciler_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import (
1414
"k8s.io/apimachinery/pkg/types"
1515

1616
"github.com/tilt-dev/tilt/internal/controllers/fake"
17-
"github.com/tilt-dev/tilt/internal/testutils/tempdir"
1817
"github.com/tilt-dev/tilt/internal/xdg"
1918
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
20-
"github.com/tilt-dev/wmclient/pkg/os/temp"
2119
)
2220

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

209207
func newFixture(t *testing.T) *fixture {
210208
cfb := fake.NewControllerFixtureBuilder(t)
211-
tmpDir, err := temp.NewDir(tempdir.SanitizeFileName(t.Name()))
212-
require.NoError(t, err)
213-
t.Cleanup(func() { _ = os.RemoveAll(tmpDir.Path()) })
214-
215-
base := xdg.FakeBase{Dir: tmpDir.Path()}
209+
tmpDir := t.TempDir()
210+
base := xdg.FakeBase{Dir: tmpDir}
216211
r, err := NewReconciler(cfb.Client, cfb.Store, base)
217212
require.NoError(t, err)
218213

internal/filelock/with_lock.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ func withLock(filename string, lt lockType, action func() error) error {
2424
if err != nil {
2525
return err
2626
}
27+
defer func() {
28+
_ = lockfile.Close()
29+
}()
2730
err = lock(lockfile, lt)
2831
if err != nil {
2932
return err
3033
}
31-
defer func() { _ = Unlock(lockfile) }()
34+
defer func() {
35+
_ = Unlock(lockfile)
36+
}()
3237
return action()
3338
}

internal/testutils/tempdir/temp_dir_fixture.go

+8-28
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import (
44
"os"
55
"path/filepath"
66
"regexp"
7-
"runtime"
87
"strings"
98
"testing"
10-
11-
"github.com/tilt-dev/wmclient/pkg/os/temp"
129
)
1310

1411
type TempDirFixture struct {
1512
t testing.TB
16-
dir *temp.TempDir
13+
dir string
1714
oldDir string
1815
}
1916

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

2724
func NewTempDirFixture(t testing.TB) *TempDirFixture {
28-
dir, err := temp.NewDir(SanitizeFileName(t.Name()))
29-
if err != nil {
30-
t.Fatalf("Error making temp dir: %v", err)
31-
}
32-
33-
ret := &TempDirFixture{
25+
f := &TempDirFixture{
3426
t: t,
35-
dir: dir,
27+
dir: t.TempDir(),
3628
}
37-
38-
t.Cleanup(ret.tearDown)
39-
40-
return ret
29+
t.Cleanup(f.tearDown)
30+
return f
4131
}
4232

4333
func (f *TempDirFixture) T() testing.TB {
4434
return f.t
4535
}
4636

4737
func (f *TempDirFixture) Path() string {
48-
return f.dir.Path()
38+
return f.dir
4939
}
5040

5141
func (f *TempDirFixture) Chdir() {
@@ -154,11 +144,11 @@ func (f *TempDirFixture) Rm(pathInRepo string) {
154144
}
155145

156146
func (f *TempDirFixture) NewFile(prefix string) (*os.File, error) {
157-
return os.CreateTemp(f.dir.Path(), prefix)
147+
return os.CreateTemp(f.dir, prefix)
158148
}
159149

160150
func (f *TempDirFixture) TempDir(prefix string) string {
161-
name, err := os.MkdirTemp(f.dir.Path(), prefix)
151+
name, err := os.MkdirTemp(f.dir, prefix)
162152
if err != nil {
163153
f.t.Fatal(err)
164154
}
@@ -172,14 +162,4 @@ func (f *TempDirFixture) tearDown() {
172162
f.t.Fatal(err)
173163
}
174164
}
175-
176-
err := f.dir.TearDown()
177-
if err != nil && runtime.GOOS == "windows" &&
178-
(strings.Contains(err.Error(), "The process cannot access the file") ||
179-
strings.Contains(err.Error(), "Access is denied")) {
180-
// NOTE(nick): I'm not convinced that this is a real problem.
181-
// I think it might just be clean up of file notification I/O.
182-
} else if err != nil {
183-
f.t.Fatal(err)
184-
}
185165
}

vendor/github.com/tilt-dev/wmclient/pkg/env/debug.go

-9
This file was deleted.

vendor/github.com/tilt-dev/wmclient/pkg/os/temp/dir.go

-15
This file was deleted.

vendor/github.com/tilt-dev/wmclient/pkg/os/temp/persistent.go

-40
This file was deleted.

vendor/github.com/tilt-dev/wmclient/pkg/os/temp/temp.go

-79
This file was deleted.

vendor/modules.txt

-2
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,6 @@ github.com/tilt-dev/tilt-apiserver/pkg/storage/filepath
756756
## explicit; go 1.13
757757
github.com/tilt-dev/wmclient/pkg/analytics
758758
github.com/tilt-dev/wmclient/pkg/dirs
759-
github.com/tilt-dev/wmclient/pkg/env
760-
github.com/tilt-dev/wmclient/pkg/os/temp
761759
# github.com/tonistiigi/fsutil v0.0.0-20240424095704-91a3fc46842c
762760
## explicit; go 1.20
763761
github.com/tonistiigi/fsutil

0 commit comments

Comments
 (0)