Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/minikube/download/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ func binaryWithChecksumURL(binaryName, version, osName, archName, binaryURL stri

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

Expand Down
23 changes: 23 additions & 0 deletions pkg/minikube/download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import (
"fmt"
"io/fs"
"os"
"path/filepath"
"sync"
"testing"
"time"

"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
)

// Force download tests to run in serial.
Expand Down Expand Up @@ -242,3 +244,24 @@ func testPreloadWithCachedSizeZero(t *testing.T) {
t.Errorf("Expected only 1 download attempt but got %v!", downloadNum)
}
}

func TestBinaryCreatesBinariesDir(t *testing.T) {
// mock download function that creates a fake binary file
DownloadMock = func(src, dst string) error {
// create a fake binary file at dst
return os.WriteFile(dst, []byte("fake-binary"), 0755)
}

_, err := Binary("kubectl", "v1.31.0", "linux", "amd64", "")
if err != nil {
t.Fatalf("Binary() failed: %v", err)
}

// check that the bin directory was created
targetDir := filepath.Join(
localpath.MiniPath(), "cache", "bin", "linux", "amd64", "v1.31.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, to make it even better squash this commit into the first one. Having this in git history is not helpful.

)
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
t.Errorf("Expected bin dir %s to exist, but it does not", targetDir)
}
}