diff --git a/pkg/client/client.go b/pkg/client/client.go index dda5f26a..a6820db5 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -918,7 +918,12 @@ func (c *KpmClient) AcquireTheLatestOciVersion(ociSource pkg.Oci) (string, error // Download will download the dependency to the local path. func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (*pkg.Dependency, error) { if dep.Source.Git != nil { - _, err := c.DownloadFromGit(dep.Source.Git, localPath) + err := c.DepDownloader.Download(*downloader.NewDownloadOptions( + downloader.WithLocalPath(localPath), + downloader.WithSource(dep.Source), + downloader.WithLogWriter(c.logWriter), + downloader.WithSettings(c.settings), + )) if err != nil { return nil, err } diff --git a/pkg/downloader/downloader_test.go b/pkg/downloader/downloader_test.go index 8f0e3652..46b94276 100644 --- a/pkg/downloader/downloader_test.go +++ b/pkg/downloader/downloader_test.go @@ -21,17 +21,20 @@ func getTestDir(subDir string) string { } func TestOciDownloader(t *testing.T) { - path := getTestDir("test_oci") + ociTestDir := getTestDir("oci_test_dir") + if err := os.MkdirAll(ociTestDir, os.ModePerm); err != nil { + t.Fatal(err) + } defer func() { - _ = os.RemoveAll(path) + _ = os.RemoveAll(ociTestDir) }() - ociDownloader := OciDownloader{ + downloader := OciDownloader{ Platform: "linux/amd64", } - err := ociDownloader.Download(*NewDownloadOptions( + options := NewDownloadOptions( WithSource(pkg.Source{ Oci: &pkg.Oci{ Reg: "ghcr.io", @@ -39,9 +42,36 @@ func TestOciDownloader(t *testing.T) { Tag: "0.0.3", }, }), - WithLocalPath(path), + WithLocalPath(ociTestDir), + ) + + err := downloader.Download(*options) + + assert.Equal(t, err, nil) + assert.Equal(t, true, utils.DirExists(filepath.Join(ociTestDir, "artifact.tgz"))) + + gitTestDir := getTestDir("git_test_dir") + if err := os.MkdirAll(gitTestDir, os.ModePerm); err != nil { + t.Fatal(err) + } + + defer func() { + _ = os.RemoveAll(gitTestDir) + }() + + gitDownloader := GitDownloader{} + + err = gitDownloader.Download(*NewDownloadOptions( + WithSource(pkg.Source{ + Git: &pkg.Git{ + Url: "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", + Commit: "ade147b", + }, + }), + WithLocalPath(gitTestDir), )) assert.Equal(t, err, nil) - assert.Equal(t, true, utils.DirExists(filepath.Join(path, "artifact.tgz"))) + assert.Equal(t, false, utils.DirExists(filepath.Join(gitTestDir, "some_expected_file"))) } +