minikube/test/integration/a_download_only_test.go

90 lines
3.0 KiB
Go
Raw Normal View History

2019-07-30 00:57:36 +00:00
// +build integration
/*
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.
*/
// a_download_only_test.go filename starts with a, for the purpose that it runs before all parallel tests and downloads the images and caches them.
2019-07-30 00:57:36 +00:00
package integration
2019-07-30 00:57:36 +00:00
import (
"fmt"
"os"
"path/filepath"
"runtime"
2019-07-30 00:57:36 +00:00
"testing"
"time"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
pkgutil "k8s.io/minikube/pkg/util"
"k8s.io/minikube/test/integration/util"
2019-07-30 00:57:36 +00:00
)
// Note this test runs before all because filename is alpahbetically first
// is used to cache images and binaries used by other parallel tests to avoid redownloading.
// TestDownloadOnly tests the --download-only option
2019-07-30 00:57:36 +00:00
func TestDownloadOnly(t *testing.T) {
p := profileName(t)
2019-07-30 00:57:36 +00:00
mk := NewMinikubeRunner(t, p)
2019-07-30 04:52:05 +00:00
if !isTestNoneDriver() { // none driver doesnt need to be deleted
defer mk.TearDown(t)
2019-07-30 04:52:05 +00:00
}
2019-07-30 03:40:41 +00:00
t.Run("Oldest", func(t *testing.T) {
stdout, stderr, err := mk.Start("--download-only", fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion))
if err != nil {
2019-08-01 16:58:43 +00:00
t.Errorf("%s minikube --download-only failed : %v\nstdout: %s\nstderr: %s", p, err, stdout, stderr)
}
})
t.Run("Newest", func(t *testing.T) {
stdout, stderr, err := mk.Start("--download-only", fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion))
if err != nil {
2019-08-01 16:58:43 +00:00
t.Errorf("%s minikube --download-only failed : %v\nstdout: %s\nstderr: %s", p, err, stdout, stderr)
}
// TODO: add test to check if files are downloaded
})
t.Run("DownloadLatestRelease", func(t *testing.T) {
2019-08-01 20:44:57 +00:00
dest := filepath.Join(*testdataDir, fmt.Sprintf("minikube-%s-%s-latest-stable", runtime.GOOS, runtime.GOARCH))
err := downloadMinikubeBinary(dest, "latest")
if err != nil {
t.Errorf("erorr downloading the latest minikube release %v", err)
}
})
2019-07-30 00:57:36 +00:00
}
2019-07-31 05:48:42 +00:00
// downloadMinikubeBinary downloads the minikube binary from github used by TestVersionUpgrade
// acts as a test setup for TestVersionUpgrade
func downloadMinikubeBinary(dest string, version string) error {
// Grab latest release binary
url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS)
download := func() error {
return getter.GetFile(dest, url)
}
2019-07-31 05:48:42 +00:00
if err := util.RetryX(download, 13*time.Second, 5*time.Minute); err != nil {
return errors.Wrap(err, "Failed to get latest release binary")
}
if runtime.GOOS != "windows" {
if err := os.Chmod(dest, 0700); err != nil {
return err
}
}
return nil
}