diff --git a/pkg/client/client.go b/pkg/client/client.go index dda5f26a..c818a992 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/client/client_test.go b/pkg/client/client_test.go index d63e270e..d4803b7d 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -50,7 +50,7 @@ func initTestDir(subDir string) string { return testDir } -// TestDownloadGit test download from oci registry. +// TestDownloadOci test download from oci registry. func TestDownloadOci(t *testing.T) { testPath := filepath.Join(getTestDir("download"), "helloworld_0.1.2") err := os.MkdirAll(testPath, 0755) diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index 24a17125..e0b4a4a5 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -4,10 +4,8 @@ import ( "errors" "fmt" "io" - "path/filepath" v1 "github.com/opencontainers/image-spec/specs-go/v1" - "kcl-lang.io/kpm/pkg/constants" "kcl-lang.io/kpm/pkg/git" "kcl-lang.io/kpm/pkg/oci" pkg "kcl-lang.io/kpm/pkg/package" @@ -170,7 +168,7 @@ func (d *GitDownloader) Download(opts DownloadOptions) error { git.WithBranch(gitSource.Branch), git.WithTag(gitSource.Tag), git.WithRepoURL(gitSource.Url), - git.WithLocalPath(filepath.Join(opts.LocalPath, constants.GitEntry)), + git.WithLocalPath(opts.LocalPath), ) if err != nil { diff --git a/pkg/downloader/downloader_test.go b/pkg/downloader/downloader_test.go index 8f0e3652..bc16d845 100644 --- a/pkg/downloader/downloader_test.go +++ b/pkg/downloader/downloader_test.go @@ -21,10 +21,13 @@ func getTestDir(subDir string) string { } func TestOciDownloader(t *testing.T) { - path := getTestDir("test_oci") + path_oci := getTestDir("test_oci") + if err := os.MkdirAll(path_oci, os.ModePerm); err != nil { + t.Fatal(err) + } defer func() { - _ = os.RemoveAll(path) + _ = os.RemoveAll(path_oci) }() ociDownloader := OciDownloader{ @@ -39,9 +42,32 @@ func TestOciDownloader(t *testing.T) { Tag: "0.0.3", }, }), - WithLocalPath(path), + WithLocalPath(path_oci), + )) + + assert.Equal(t, err, nil) + assert.Equal(t, true, utils.DirExists(filepath.Join(path_oci, "artifact.tgz"))) + + path_git := getTestDir("test_git") + if err := os.MkdirAll(path_oci, os.ModePerm); err != nil { + t.Fatal(err) + } + + defer func() { + _ = os.RemoveAll(path_git) + }() + + 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(path_git), )) assert.Equal(t, err, nil) - assert.Equal(t, true, utils.DirExists(filepath.Join(path, "artifact.tgz"))) }