Skip to content

Commit

Permalink
Add drivers.InstallOrUpdate acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josedonizetti committed Sep 4, 2019
1 parent fab27d5 commit 87f2109
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,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})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/drivers/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
69 changes: 69 additions & 0 deletions test/integration/driver_update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
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)
}
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 87f2109

Please sign in to comment.