提交 0cf4921c 编写于 作者: J josedonizetti

Add drivers.InstallOrUpdate acceptance tests

上级 30e75c3c
......@@ -1038,7 +1038,7 @@ func validateDriverVersion(vmDriver string) {
case constants.DriverKvm2:
driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverKvm2)
targetDir := constants.MakeMiniPath("bin")
err := drivers.Download(driverExecutable, targetDir, minikubeVersion)
err := drivers.InstallOrUpdate(driverExecutable, targetDir, minikubeVersion)
if err != nil {
out.WarningT("Error downloading driver: {{.error}}", out.V{"error": err})
}
......
......@@ -151,8 +151,8 @@ func fixPermissions(path string) error {
return nil
}
// Download downloads driver if it is not present, or if the version is old
func Download(driver, destination string, minikubeVersion semver.Version) error {
// InstallOrUpdate downloads driver if it is not present, or updates it if there's a newer version
func InstallOrUpdate(driver, destination string, minikubeVersion semver.Version) error {
_, err := exec.LookPath(driver)
// if file driver doesn't exist, download it
if err != nil {
......
/*
Copyright 2019 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package integration
import (
"fmt"
"io/ioutil"
"os"
"path"
"runtime"
"testing"
"github.com/blang/semver"
"k8s.io/minikube/pkg/drivers"
)
func TestDriverInstallOrUpdate(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip()
}
tests := []struct {
name string
path string
}{
{name: "driver-without-version-support", path: "./testdata/kvm2-driver-without-version"},
{name: "driver-with-older-version", path: "./testdata/kvm2-driver-without-version"},
}
for _, tc := range tests {
dir, err := ioutil.TempDir("", tc.name)
if err != nil {
t.Fatalf("Expected to create tempdir. test: %s, got: %v", tc.name, err)
}
defer os.RemoveAll(dir)
os.Setenv("PATH", fmt.Sprintf("%s:%s", tc.path, os.Getenv("PATH")))
newerVersion, err := semver.Make("1.1.3")
if err != nil {
t.Fatalf("Expected new semver. test: %v, got: %v", tc.name, err)
}
err = drivers.InstallOrUpdate("docker-machine-driver-kvm2", dir, newerVersion)
if err != nil {
t.Fatalf("Expected to update driver. test: %s, got: %v", tc.name, err)
}
_, err = os.Stat(path.Join(dir, "docker-machine-driver-kvm2"))
if err != nil {
t.Fatalf("Expected driver to be download. test: %s, got: %v", tc.name, err)
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册