commit
7367c72a3e
|
|
@ -115,7 +115,7 @@ func hideEnv(t *testing.T) func(t *testing.T) {
|
|||
func TestPreRunDirectories(t *testing.T) {
|
||||
// Make sure we create the required directories.
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
|
||||
runCommand(RootCmd.PersistentPreRun)
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
func Test_createDiskImage(t *testing.T) {
|
||||
tmpdir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tmpdir)
|
||||
defer tests.RemoveTempDir(tmpdir)
|
||||
|
||||
sshPath := filepath.Join(tmpdir, "ssh")
|
||||
if err := ioutil.WriteFile(sshPath, []byte("mysshkey"), 0644); err != nil {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ var validLeases = []byte(`{
|
|||
|
||||
func Test_getIpAddressFromFile(t *testing.T) {
|
||||
tmpdir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tmpdir)
|
||||
defer tests.RemoveTempDir(tmpdir)
|
||||
|
||||
dhcpFile := filepath.Join(tmpdir, "dhcp")
|
||||
if err := ioutil.WriteFile(dhcpFile, validLeases, 0644); err != nil {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import (
|
|||
|
||||
func TestSetupCerts(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
|
||||
k8s := config.KubernetesConfig{
|
||||
APIServerName: constants.APIServerName,
|
||||
|
|
|
|||
|
|
@ -19,18 +19,15 @@ package machine
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/driver"
|
||||
"k8s.io/minikube/pkg/minikube/localpath"
|
||||
_ "k8s.io/minikube/pkg/minikube/registry/drvs/virtualbox"
|
||||
testutil "k8s.io/minikube/pkg/minikube/tests"
|
||||
)
|
||||
|
||||
const vboxConfig = `
|
||||
|
|
@ -113,24 +110,9 @@ func TestLocalClientNewHost(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func makeTempDir() string {
|
||||
tempDir, err := ioutil.TempDir("", "minipath")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tempDir = filepath.Join(tempDir, ".minikube")
|
||||
os.Setenv(localpath.MinikubeHome, tempDir)
|
||||
return localpath.MiniPath()
|
||||
}
|
||||
|
||||
func TestRunNotDriver(t *testing.T) {
|
||||
tempDir := makeTempDir()
|
||||
defer func() { //clean up tempdir
|
||||
err := os.RemoveAll(tempDir)
|
||||
if err != nil {
|
||||
t.Errorf("failed to clean up temp folder %q", tempDir)
|
||||
}
|
||||
}()
|
||||
tempDir := testutil.MakeTempDir()
|
||||
defer testutil.RemoveTempDir(tempDir)
|
||||
StartDriver()
|
||||
if !localbinary.CurrentBinaryIsDockerMachine {
|
||||
t.Fatal("CurrentBinaryIsDockerMachine not set. This will break driver initialization.")
|
||||
|
|
@ -140,8 +122,8 @@ func TestRunNotDriver(t *testing.T) {
|
|||
func TestRunDriver(t *testing.T) {
|
||||
// This test is a bit complicated. It verifies that when the root command is
|
||||
// called with the proper environment variables, we setup the libmachine driver.
|
||||
tempDir := makeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
tempDir := testutil.MakeTempDir()
|
||||
defer testutil.RemoveTempDir(tempDir)
|
||||
|
||||
os.Setenv(localbinary.PluginEnvKey, localbinary.PluginEnvVal)
|
||||
os.Setenv(localbinary.PluginEnvDriverName, driver.VirtualBox)
|
||||
|
|
|
|||
|
|
@ -17,26 +17,16 @@ limitations under the License.
|
|||
package machine
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"k8s.io/minikube/pkg/minikube/localpath"
|
||||
testutil "k8s.io/minikube/pkg/minikube/tests"
|
||||
"k8s.io/minikube/pkg/minikube/vmpath"
|
||||
)
|
||||
|
||||
func setupTestDir() (string, error) {
|
||||
path, err := ioutil.TempDir("", "minipath")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
os.Setenv(localpath.MinikubeHome, path)
|
||||
return path, err
|
||||
}
|
||||
|
||||
func TestAssetsFromDir(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
|
|
@ -107,17 +97,8 @@ func TestAssetsFromDir(t *testing.T) {
|
|||
|
||||
for _, test := range tests {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
testDir, err := setupTestDir()
|
||||
defer func() { //clean up tempdir
|
||||
err := os.RemoveAll(testDir)
|
||||
if err != nil {
|
||||
t.Errorf("failed to clean up temp folder %q", testDir)
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
t.Errorf("got unexpected error creating test dir: %v", err)
|
||||
return
|
||||
}
|
||||
testDir := testutil.MakeTempDir()
|
||||
defer testutil.RemoveTempDir(testDir)
|
||||
|
||||
testDirs = append(testDirs, testDir)
|
||||
testFileBaseDir := filepath.Join(testDir, test.baseDir)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func TestMaybePrintUpdateTextFromGithub(t *testing.T) {
|
|||
|
||||
func TestShouldCheckURL(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
|
||||
lastUpdateCheckFilePath := filepath.Join(tempDir, "last_update_check")
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ func TestGetLatestVersionFromURLMalformed(t *testing.T) {
|
|||
|
||||
func TestMaybePrintUpdateText(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
outputBuffer := tests.NewFakeFile()
|
||||
out.SetErrFile(outputBuffer)
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,13 @@ func MakeTempDir() string {
|
|||
return localpath.MiniPath()
|
||||
}
|
||||
|
||||
func RemoveTempDir(tempdir string) {
|
||||
if filepath.Base(tempdir) == ".minikube" {
|
||||
tempdir = filepath.Dir(tempdir)
|
||||
}
|
||||
os.RemoveAll(tempdir)
|
||||
}
|
||||
|
||||
// FakeFile satisfies fdWriter
|
||||
type FakeFile struct {
|
||||
b bytes.Buffer
|
||||
|
|
|
|||
Loading…
Reference in New Issue