From f76ef159fc768e4b00fd133eeac55c60433b698b Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Wed, 29 May 2024 22:04:45 +0530 Subject: [PATCH 1/4] feat: added tests for gitDownload Signed-off-by: Asish Kumar --- pkg/downloader/downloader_test.go | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) 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"))) } From 6359c7732a53cfaec91cce416723995ce4168c72 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Wed, 29 May 2024 22:10:49 +0530 Subject: [PATCH 2/4] typo fix in TestDownloadOci in client_test.go Signed-off-by: Asish Kumar --- pkg/client/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index d0df4502..2d1ec08b 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) From 33f0bac77a81d9cfe8d4286b2f4ce4af8f295c6a Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Wed, 29 May 2024 22:18:00 +0530 Subject: [PATCH 3/4] feat: change git download from DownloadFromGit to GitDownloader Signed-off-by: Asish Kumar --- pkg/client/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index c2042e37..8efa5476 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -961,7 +961,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 } From e496a6f6578cecef3a669ac42c9f4043c221a3b8 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Thu, 30 May 2024 15:56:05 +0530 Subject: [PATCH 4/4] removed git subdirectory when download from git Downloader Signed-off-by: Asish Kumar --- pkg/downloader/downloader.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 {