Skip to content

Commit 426764c

Browse files
committed
use teesting.TempDir instead of os.MkdirTemp
Signed-off-by: sivchari <[email protected]>
1 parent ad97dc5 commit 426764c

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

cmd/clusterctl/client/repository/client_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package repository
1818

1919
import (
2020
"context"
21-
"os"
2221
"testing"
2322

2423
. "github.com/onsi/gomega"
@@ -34,8 +33,7 @@ func Test_newRepositoryClient_LocalFileSystemRepository(t *testing.T) {
3433

3534
ctx := context.Background()
3635

37-
tmpDir := createTempDir(t)
38-
defer os.RemoveAll(tmpDir)
36+
tmpDir := t.TempDir()
3937

4038
dst1 := createLocalTestProviderFile(t, tmpDir, "bootstrap-foo/v1.0.0/bootstrap-components.yaml", "")
4139
dst2 := createLocalTestProviderFile(t, tmpDir, "bootstrap-bar/v2.0.0/bootstrap-components.yaml", "")

cmd/clusterctl/client/repository/overrides_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ func TestGetLocalOverrides(t *testing.T) {
100100
t.Run("returns contents of file successfully", func(t *testing.T) {
101101
g := NewWithT(t)
102102

103-
tmpDir := createTempDir(t)
104-
defer os.RemoveAll(tmpDir)
103+
tmpDir := t.TempDir()
105104

106105
createLocalTestProviderFile(t, tmpDir, "infrastructure-myinfra/v1.0.1/infra-comp.yaml", "foo: bar")
107106

cmd/clusterctl/client/repository/repository_local_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,6 @@ func Test_localRepository_newLocalRepository(t *testing.T) {
129129
}
130130
}
131131

132-
func createTempDir(t *testing.T) string {
133-
t.Helper()
134-
135-
dir, err := os.MkdirTemp("", "cc")
136-
if err != nil {
137-
t.Fatalf("err: %s", err)
138-
}
139-
return dir
140-
}
141-
142132
func createLocalTestProviderFile(t *testing.T, tmpDir, path, msg string) string {
143133
t.Helper()
144134

@@ -155,8 +145,7 @@ func createLocalTestProviderFile(t *testing.T, tmpDir, path, msg string) string
155145
func Test_localRepository_newLocalRepository_Latest(t *testing.T) {
156146
g := NewWithT(t)
157147

158-
tmpDir := createTempDir(t)
159-
defer os.RemoveAll(tmpDir)
148+
tmpDir := t.TempDir()
160149

161150
// Create several release directories
162151
createLocalTestProviderFile(t, tmpDir, "bootstrap-foo/v1.0.0/bootstrap-components.yaml", "foo: bar")
@@ -182,8 +171,7 @@ func Test_localRepository_newLocalRepository_Latest(t *testing.T) {
182171
}
183172

184173
func Test_localRepository_GetFile(t *testing.T) {
185-
tmpDir := createTempDir(t)
186-
defer os.RemoveAll(tmpDir)
174+
tmpDir := t.TempDir()
187175

188176
// Provider 1: URL is for the only release available
189177
dst1 := createLocalTestProviderFile(t, tmpDir, "bootstrap-foo/v1.0.0/bootstrap-components.yaml", "foo: bar")
@@ -319,8 +307,7 @@ func Test_localRepository_GetFile(t *testing.T) {
319307
}
320308

321309
func Test_localRepository_GetVersions(t *testing.T) {
322-
tmpDir := createTempDir(t)
323-
defer os.RemoveAll(tmpDir)
310+
tmpDir := t.TempDir()
324311

325312
// Provider 1: has a single release available
326313
dst1 := createLocalTestProviderFile(t, tmpDir, "bootstrap-foo/v1.0.0/bootstrap-components.yaml", "foo: bar")

0 commit comments

Comments
 (0)