Skip to content

Commit

Permalink
Create unit test for excluding binaries from caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyDev committed May 20, 2021
1 parent 9fb9e94 commit b441330
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/minikube/machine/cache_binaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"

"k8s.io/minikube/pkg/minikube/assets"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit b441330

Please sign in to comment.