Create unit test for excluding binaries from caching.

pull/11461/head
Andriy Dzikh 2021-05-18 15:57:22 -07:00
parent 9fb9e940f1
commit b441330f7e
1 changed files with 34 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"k8s.io/minikube/pkg/minikube/assets"
@ -131,3 +132,36 @@ func TestCacheBinariesForBootstrapper(t *testing.T) {
})
}
}
func TestExcludedBinariesNotDownloaded(t *testing.T) {
clusterBootstrapper := bootstrapper.Kubeadm
binaryList := bootstrapper.GetCachedBinaryList(clusterBootstrapper)
binaryToExclude := binaryList[0]
download.DownloadMock = func(src, dst string) error {
if strings.Contains(src, binaryToExclude) {
t.Errorf("Excluded binary was downloaded! Binary to exclude: %s", binaryToExclude)
}
return download.CreateDstDownloadMock(src, dst)
}
oldMinikubeHome := os.Getenv("MINIKUBE_HOME")
defer os.Setenv("MINIKUBE_HOME", oldMinikubeHome)
minikubeHome, err := ioutil.TempDir("/tmp", "")
if err != nil {
t.Fatalf("error during creating tmp dir: %v", err)
}
os.Setenv("MINIKUBE_HOME", minikubeHome)
defer func() { // clean up tempdir
err := os.RemoveAll(minikubeHome)
if err != nil {
t.Errorf("failed to clean up temp folder %q", minikubeHome)
}
}()
if err := CacheBinariesForBootstrapper("v1.16.0", clusterBootstrapper, []string{binaryToExclude}); err != nil {
t.Errorf("Failed to cache binaries: %v", err)
}
}