From e80cf9ce71a0158adada2afa4b9160ea891ef627 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Fri, 17 Jul 2020 10:41:16 +0200 Subject: [PATCH] Use temporary directory when creating temporary file in tests Kubernetes-commit: a7529f4cd90ea6f662e1398608eccd86e886026f --- pkg/cmd/config/config_test.go | 12 ++++++------ pkg/cmd/config/current_context_test.go | 2 +- pkg/cmd/config/delete_cluster_test.go | 2 +- pkg/cmd/config/delete_context_test.go | 2 +- pkg/cmd/config/get_clusters_test.go | 2 +- pkg/cmd/config/get_contexts_test.go | 2 +- pkg/cmd/config/rename_context_test.go | 2 +- pkg/cmd/config/set_test.go | 2 +- pkg/cmd/get/customcolumn_flags_test.go | 2 +- pkg/cmd/testing/fake.go | 2 +- pkg/cmd/util/helpers_test.go | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/cmd/config/config_test.go b/pkg/cmd/config/config_test.go index c7648b11..53e11113 100644 --- a/pkg/cmd/config/config_test.go +++ b/pkg/cmd/config/config_test.go @@ -261,7 +261,7 @@ func TestAdditionalAuth(t *testing.T) { } func TestEmbedClientCert(t *testing.T) { - fakeCertFile, _ := ioutil.TempFile("", "") + fakeCertFile, _ := ioutil.TempFile(os.TempDir(), "") defer os.Remove(fakeCertFile.Name()) fakeData := []byte("fake-data") ioutil.WriteFile(fakeCertFile.Name(), fakeData, 0600) @@ -280,7 +280,7 @@ func TestEmbedClientCert(t *testing.T) { } func TestEmbedClientKey(t *testing.T) { - fakeKeyFile, _ := ioutil.TempFile("", "") + fakeKeyFile, _ := ioutil.TempFile(os.TempDir(), "") defer os.Remove(fakeKeyFile.Name()) fakeData := []byte("fake-data") ioutil.WriteFile(fakeKeyFile.Name(), fakeData, 0600) @@ -326,7 +326,7 @@ func TestEmbedNoKeyOrCertDisallowed(t *testing.T) { } func TestEmptyTokenAndCertAllowed(t *testing.T) { - fakeCertFile, _ := ioutil.TempFile("", "cert-file") + fakeCertFile, _ := ioutil.TempFile(os.TempDir(), "cert-file") defer os.Remove(fakeCertFile.Name()) expectedConfig := newRedFederalCowHammerConfig() authInfo := clientcmdapi.NewAuthInfo() @@ -569,7 +569,7 @@ func TestUnsetBytes(t *testing.T) { } func TestCAClearsInsecure(t *testing.T) { - fakeCAFile, _ := ioutil.TempFile("", "ca-file") + fakeCAFile, _ := ioutil.TempFile(os.TempDir(), "ca-file") defer os.Remove(fakeCAFile.Name()) clusterInfoWithInsecure := clientcmdapi.NewCluster() clusterInfoWithInsecure.InsecureSkipTLSVerify = true @@ -638,7 +638,7 @@ func TestInsecureClearsCA(t *testing.T) { } func TestCADataClearsCA(t *testing.T) { - fakeCAFile, _ := ioutil.TempFile("", "") + fakeCAFile, _ := ioutil.TempFile(os.TempDir(), "") defer os.Remove(fakeCAFile.Name()) fakeData := []byte("cadata") ioutil.WriteFile(fakeCAFile.Name(), fakeData, 0600) @@ -852,7 +852,7 @@ func TestToBool(t *testing.T) { } func testConfigCommand(args []string, startingConfig clientcmdapi.Config, t *testing.T) (string, clientcmdapi.Config) { - fakeKubeFile, _ := ioutil.TempFile("", "") + fakeKubeFile, _ := ioutil.TempFile(os.TempDir(), "") defer os.Remove(fakeKubeFile.Name()) err := clientcmd.WriteToFile(startingConfig, fakeKubeFile.Name()) if err != nil { diff --git a/pkg/cmd/config/current_context_test.go b/pkg/cmd/config/current_context_test.go index 69b466f4..139b79a1 100644 --- a/pkg/cmd/config/current_context_test.go +++ b/pkg/cmd/config/current_context_test.go @@ -57,7 +57,7 @@ func TestCurrentContextWithUnsetContext(t *testing.T) { } func (test currentContextTest) run(t *testing.T) { - fakeKubeFile, err := ioutil.TempFile("", "") + fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/config/delete_cluster_test.go b/pkg/cmd/config/delete_cluster_test.go index 5e7457a6..3becba3f 100644 --- a/pkg/cmd/config/delete_cluster_test.go +++ b/pkg/cmd/config/delete_cluster_test.go @@ -53,7 +53,7 @@ func TestDeleteCluster(t *testing.T) { } func (test deleteClusterTest) run(t *testing.T) { - fakeKubeFile, err := ioutil.TempFile("", "") + fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/config/delete_context_test.go b/pkg/cmd/config/delete_context_test.go index 8f7b9582..04bbe17c 100644 --- a/pkg/cmd/config/delete_context_test.go +++ b/pkg/cmd/config/delete_context_test.go @@ -53,7 +53,7 @@ func TestDeleteContext(t *testing.T) { } func (test deleteContextTest) run(t *testing.T) { - fakeKubeFile, err := ioutil.TempFile("", "") + fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/config/get_clusters_test.go b/pkg/cmd/config/get_clusters_test.go index 9eaf808f..13186a88 100644 --- a/pkg/cmd/config/get_clusters_test.go +++ b/pkg/cmd/config/get_clusters_test.go @@ -57,7 +57,7 @@ func TestGetClustersEmpty(t *testing.T) { } func (test getClustersTest) run(t *testing.T) { - fakeKubeFile, err := ioutil.TempFile("", "") + fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/config/get_contexts_test.go b/pkg/cmd/config/get_contexts_test.go index dbf5dbe1..d97d43ca 100644 --- a/pkg/cmd/config/get_contexts_test.go +++ b/pkg/cmd/config/get_contexts_test.go @@ -144,7 +144,7 @@ func TestGetContextsSelectOneOfTwo(t *testing.T) { } func (test getContextsTest) run(t *testing.T) { - fakeKubeFile, err := ioutil.TempFile("", "") + fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/config/rename_context_test.go b/pkg/cmd/config/rename_context_test.go index 01edde9f..cfacb901 100644 --- a/pkg/cmd/config/rename_context_test.go +++ b/pkg/cmd/config/rename_context_test.go @@ -103,7 +103,7 @@ func TestRenameToAlreadyExistingContext(t *testing.T) { } func (test renameContextTest) run(t *testing.T) { - fakeKubeFile, _ := ioutil.TempFile("", "") + fakeKubeFile, _ := ioutil.TempFile(os.TempDir(), "") defer os.Remove(fakeKubeFile.Name()) err := clientcmd.WriteToFile(test.initialConfig, fakeKubeFile.Name()) if err != nil { diff --git a/pkg/cmd/config/set_test.go b/pkg/cmd/config/set_test.go index 3fa886d1..87afd7a1 100644 --- a/pkg/cmd/config/set_test.go +++ b/pkg/cmd/config/set_test.go @@ -55,7 +55,7 @@ func TestSetConfigCurrentContext(t *testing.T) { } func (test setConfigTest) run(t *testing.T) { - fakeKubeFile, err := ioutil.TempFile("", "") + fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/get/customcolumn_flags_test.go b/pkg/cmd/get/customcolumn_flags_test.go index 6704bdf2..01b4f371 100644 --- a/pkg/cmd/get/customcolumn_flags_test.go +++ b/pkg/cmd/get/customcolumn_flags_test.go @@ -32,7 +32,7 @@ import ( func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) { testObject := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}} - customColumnsFile, err := ioutil.TempFile("", "printers_jsonpath_flags") + customColumnsFile, err := ioutil.TempFile(os.TempDir(), "printers_jsonpath_flags") if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/cmd/testing/fake.go b/pkg/cmd/testing/fake.go index d6b3007a..3f160e4d 100644 --- a/pkg/cmd/testing/fake.go +++ b/pkg/cmd/testing/fake.go @@ -407,7 +407,7 @@ type TestFactory struct { func NewTestFactory() *TestFactory { // specify an optionalClientConfig to explicitly use in testing // to avoid polluting an existing user config. - tmpFile, err := ioutil.TempFile("", "cmdtests_temp") + tmpFile, err := ioutil.TempFile(os.TempDir(), "cmdtests_temp") if err != nil { panic(fmt.Sprintf("unable to create a fake client config: %v", err)) } diff --git a/pkg/cmd/util/helpers_test.go b/pkg/cmd/util/helpers_test.go index 1d9f1c0f..55785335 100644 --- a/pkg/cmd/util/helpers_test.go +++ b/pkg/cmd/util/helpers_test.go @@ -297,7 +297,7 @@ func testCheckError(t *testing.T, tests []checkErrTestCase) { func TestDumpReaderToFile(t *testing.T) { testString := "TEST STRING" - tempFile, err := ioutil.TempFile("", "hlpers_test_dump_") + tempFile, err := ioutil.TempFile(os.TempDir(), "hlpers_test_dump_") if err != nil { t.Errorf("unexpected error setting up a temporary file %v", err) }