Skip to content

Commit d3e6101

Browse files
committed
Move linux/darwin binaries into cache/binaries folder
1 parent 574f958 commit d3e6101

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pkg/minikube/download/binary.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ func binaryWithChecksumURL(binaryName, version, osName, archName, binaryURL stri
5353

5454
// Binary will download a binary onto the host
5555
func Binary(binary, version, osName, archName, binaryURL string) (string, error) {
56-
targetDir := localpath.MakeMiniPath("cache", osName, archName, version)
56+
// targetDir := localpath.MakeMiniPath("cache", osName, archName, version)
57+
targetDir := localpath.MakeMiniPath("cache", "binaries", osName, archName, version)
58+
if err := os.MkdirAll(targetDir, 0755); err != nil {
59+
return "", errors.Wrapf(err, "failed to create target dir %s", targetDir)
60+
}
5761
targetFilepath := path.Join(targetDir, binary)
5862
targetLock := targetFilepath + ".lock"
5963

pkg/minikube/download/download_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"io/fs"
2222
"os"
23+
"path/filepath"
2324
"sync"
2425
"testing"
2526
"time"
@@ -242,3 +243,24 @@ func testPreloadWithCachedSizeZero(t *testing.T) {
242243
t.Errorf("Expected only 1 download attempt but got %v!", downloadNum)
243244
}
244245
}
246+
247+
func TestBinaryCreatesBinariesDir(t *testing.T) {
248+
// mock download function that creates a fake binary file
249+
DownloadMock = func(src, dst string) error {
250+
// create a fake binary file at dst
251+
return os.WriteFile(dst, []byte("fake-binary"), 0755)
252+
}
253+
254+
_, err := Binary("kubectl", "v1.31.0", "linux", "amd64", "")
255+
if err != nil {
256+
t.Fatalf("Binary() failed: %v", err)
257+
}
258+
259+
// check that the binaries directory was created
260+
targetDir := filepath.Join(
261+
os.Getenv("HOME"), ".minikube", "cache", "binaries", "linux", "amd64", "v1.31.0",
262+
)
263+
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
264+
t.Errorf("Expected binaries dir %s to exist, but it does not", targetDir)
265+
}
266+
}

0 commit comments

Comments
 (0)