Use temporary directory when creating temporary file in tests
Kubernetes-commit: a7529f4cd90ea6f662e1398608eccd86e886026f
This commit is contained in:
parent
9927e214da
commit
e80cf9ce71
|
@ -261,7 +261,7 @@ func TestAdditionalAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmbedClientCert(t *testing.T) {
|
func TestEmbedClientCert(t *testing.T) {
|
||||||
fakeCertFile, _ := ioutil.TempFile("", "")
|
fakeCertFile, _ := ioutil.TempFile(os.TempDir(), "")
|
||||||
defer os.Remove(fakeCertFile.Name())
|
defer os.Remove(fakeCertFile.Name())
|
||||||
fakeData := []byte("fake-data")
|
fakeData := []byte("fake-data")
|
||||||
ioutil.WriteFile(fakeCertFile.Name(), fakeData, 0600)
|
ioutil.WriteFile(fakeCertFile.Name(), fakeData, 0600)
|
||||||
|
@ -280,7 +280,7 @@ func TestEmbedClientCert(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmbedClientKey(t *testing.T) {
|
func TestEmbedClientKey(t *testing.T) {
|
||||||
fakeKeyFile, _ := ioutil.TempFile("", "")
|
fakeKeyFile, _ := ioutil.TempFile(os.TempDir(), "")
|
||||||
defer os.Remove(fakeKeyFile.Name())
|
defer os.Remove(fakeKeyFile.Name())
|
||||||
fakeData := []byte("fake-data")
|
fakeData := []byte("fake-data")
|
||||||
ioutil.WriteFile(fakeKeyFile.Name(), fakeData, 0600)
|
ioutil.WriteFile(fakeKeyFile.Name(), fakeData, 0600)
|
||||||
|
@ -326,7 +326,7 @@ func TestEmbedNoKeyOrCertDisallowed(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyTokenAndCertAllowed(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())
|
defer os.Remove(fakeCertFile.Name())
|
||||||
expectedConfig := newRedFederalCowHammerConfig()
|
expectedConfig := newRedFederalCowHammerConfig()
|
||||||
authInfo := clientcmdapi.NewAuthInfo()
|
authInfo := clientcmdapi.NewAuthInfo()
|
||||||
|
@ -569,7 +569,7 @@ func TestUnsetBytes(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCAClearsInsecure(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())
|
defer os.Remove(fakeCAFile.Name())
|
||||||
clusterInfoWithInsecure := clientcmdapi.NewCluster()
|
clusterInfoWithInsecure := clientcmdapi.NewCluster()
|
||||||
clusterInfoWithInsecure.InsecureSkipTLSVerify = true
|
clusterInfoWithInsecure.InsecureSkipTLSVerify = true
|
||||||
|
@ -638,7 +638,7 @@ func TestInsecureClearsCA(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCADataClearsCA(t *testing.T) {
|
func TestCADataClearsCA(t *testing.T) {
|
||||||
fakeCAFile, _ := ioutil.TempFile("", "")
|
fakeCAFile, _ := ioutil.TempFile(os.TempDir(), "")
|
||||||
defer os.Remove(fakeCAFile.Name())
|
defer os.Remove(fakeCAFile.Name())
|
||||||
fakeData := []byte("cadata")
|
fakeData := []byte("cadata")
|
||||||
ioutil.WriteFile(fakeCAFile.Name(), fakeData, 0600)
|
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) {
|
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())
|
defer os.Remove(fakeKubeFile.Name())
|
||||||
err := clientcmd.WriteToFile(startingConfig, fakeKubeFile.Name())
|
err := clientcmd.WriteToFile(startingConfig, fakeKubeFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -57,7 +57,7 @@ func TestCurrentContextWithUnsetContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test currentContextTest) run(t *testing.T) {
|
func (test currentContextTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile("", "")
|
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func TestDeleteCluster(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test deleteClusterTest) run(t *testing.T) {
|
func (test deleteClusterTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile("", "")
|
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func TestDeleteContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test deleteContextTest) run(t *testing.T) {
|
func (test deleteContextTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile("", "")
|
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func TestGetClustersEmpty(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test getClustersTest) run(t *testing.T) {
|
func (test getClustersTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile("", "")
|
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ func TestGetContextsSelectOneOfTwo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test getContextsTest) run(t *testing.T) {
|
func (test getContextsTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile("", "")
|
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ func TestRenameToAlreadyExistingContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test renameContextTest) run(t *testing.T) {
|
func (test renameContextTest) run(t *testing.T) {
|
||||||
fakeKubeFile, _ := ioutil.TempFile("", "")
|
fakeKubeFile, _ := ioutil.TempFile(os.TempDir(), "")
|
||||||
defer os.Remove(fakeKubeFile.Name())
|
defer os.Remove(fakeKubeFile.Name())
|
||||||
err := clientcmd.WriteToFile(test.initialConfig, fakeKubeFile.Name())
|
err := clientcmd.WriteToFile(test.initialConfig, fakeKubeFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -55,7 +55,7 @@ func TestSetConfigCurrentContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test setConfigTest) run(t *testing.T) {
|
func (test setConfigTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile("", "")
|
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import (
|
||||||
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
|
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
|
||||||
testObject := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ type TestFactory struct {
|
||||||
func NewTestFactory() *TestFactory {
|
func NewTestFactory() *TestFactory {
|
||||||
// specify an optionalClientConfig to explicitly use in testing
|
// specify an optionalClientConfig to explicitly use in testing
|
||||||
// to avoid polluting an existing user config.
|
// to avoid polluting an existing user config.
|
||||||
tmpFile, err := ioutil.TempFile("", "cmdtests_temp")
|
tmpFile, err := ioutil.TempFile(os.TempDir(), "cmdtests_temp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("unable to create a fake client config: %v", err))
|
panic(fmt.Sprintf("unable to create a fake client config: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ func testCheckError(t *testing.T, tests []checkErrTestCase) {
|
||||||
|
|
||||||
func TestDumpReaderToFile(t *testing.T) {
|
func TestDumpReaderToFile(t *testing.T) {
|
||||||
testString := "TEST STRING"
|
testString := "TEST STRING"
|
||||||
tempFile, err := ioutil.TempFile("", "hlpers_test_dump_")
|
tempFile, err := ioutil.TempFile(os.TempDir(), "hlpers_test_dump_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error setting up a temporary file %v", err)
|
t.Errorf("unexpected error setting up a temporary file %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue