From ab10bdc6f3a7aaf6fdc29a4a9df0516f5d7f1a1f Mon Sep 17 00:00:00 2001 From: d4v1d03 Date: Thu, 30 May 2024 05:34:05 +0530 Subject: [PATCH] Revert "downloader pattern implemented with test added" This reverts commit 78e34fcfe1b5b86fd1a07a2cc34f14f4cad2a661. Signed-off-by: d4v1d03 --- pkg/client/client.go | 7 +----- pkg/downloader/downloader_test.go | 42 +++++-------------------------- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index a6820db5..dda5f26a 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -918,12 +918,7 @@ 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.DepDownloader.Download(*downloader.NewDownloadOptions( - downloader.WithLocalPath(localPath), - downloader.WithSource(dep.Source), - downloader.WithLogWriter(c.logWriter), - downloader.WithSettings(c.settings), - )) + _, err := c.DownloadFromGit(dep.Source.Git, localPath) if err != nil { return nil, err } diff --git a/pkg/downloader/downloader_test.go b/pkg/downloader/downloader_test.go index 46b94276..8f0e3652 100644 --- a/pkg/downloader/downloader_test.go +++ b/pkg/downloader/downloader_test.go @@ -21,20 +21,17 @@ func getTestDir(subDir string) string { } func TestOciDownloader(t *testing.T) { - ociTestDir := getTestDir("oci_test_dir") - if err := os.MkdirAll(ociTestDir, os.ModePerm); err != nil { - t.Fatal(err) - } + path := getTestDir("test_oci") defer func() { - _ = os.RemoveAll(ociTestDir) + _ = os.RemoveAll(path) }() - downloader := OciDownloader{ + ociDownloader := OciDownloader{ Platform: "linux/amd64", } - options := NewDownloadOptions( + err := ociDownloader.Download(*NewDownloadOptions( WithSource(pkg.Source{ Oci: &pkg.Oci{ Reg: "ghcr.io", @@ -42,36 +39,9 @@ func TestOciDownloader(t *testing.T) { Tag: "0.0.3", }, }), - 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), + WithLocalPath(path), )) assert.Equal(t, err, nil) - assert.Equal(t, false, utils.DirExists(filepath.Join(gitTestDir, "some_expected_file"))) + assert.Equal(t, true, utils.DirExists(filepath.Join(path, "artifact.tgz"))) } -