Skip to content

Commit

Permalink
Merge pull request #10918 from sivchari/use-ttmpdir
Browse files Browse the repository at this point in the history
🌱 use testing.TempDir instead of os.MkdirTemp
k8s-ci-robot authored Jul 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 5a04c4d + 426764c commit 6b0bc8a
Showing 3 changed files with 5 additions and 21 deletions.
4 changes: 1 addition & 3 deletions cmd/clusterctl/client/repository/client_test.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ package repository

import (
"context"
"os"
"testing"

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

ctx := context.Background()

tmpDir := createTempDir(t)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

dst1 := createLocalTestProviderFile(t, tmpDir, "bootstrap-foo/v1.0.0/bootstrap-components.yaml", "")
dst2 := createLocalTestProviderFile(t, tmpDir, "bootstrap-bar/v2.0.0/bootstrap-components.yaml", "")
3 changes: 1 addition & 2 deletions cmd/clusterctl/client/repository/overrides_test.go
Original file line number Diff line number Diff line change
@@ -100,8 +100,7 @@ func TestGetLocalOverrides(t *testing.T) {
t.Run("returns contents of file successfully", func(t *testing.T) {
g := NewWithT(t)

tmpDir := createTempDir(t)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

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

19 changes: 3 additions & 16 deletions cmd/clusterctl/client/repository/repository_local_test.go
Original file line number Diff line number Diff line change
@@ -129,16 +129,6 @@ func Test_localRepository_newLocalRepository(t *testing.T) {
}
}

func createTempDir(t *testing.T) string {
t.Helper()

dir, err := os.MkdirTemp("", "cc")
if err != nil {
t.Fatalf("err: %s", err)
}
return dir
}

func createLocalTestProviderFile(t *testing.T, tmpDir, path, msg string) string {
t.Helper()

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

tmpDir := createTempDir(t)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

// Create several release directories
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) {
}

func Test_localRepository_GetFile(t *testing.T) {
tmpDir := createTempDir(t)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

// Provider 1: URL is for the only release available
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) {
}

func Test_localRepository_GetVersions(t *testing.T) {
tmpDir := createTempDir(t)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

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

0 comments on commit 6b0bc8a

Please sign in to comment.