diff --git a/pkg/client/add_test.go b/pkg/client/add_test.go index 4e250746..6f239634 100644 --- a/pkg/client/add_test.go +++ b/pkg/client/add_test.go @@ -1,6 +1,7 @@ package client import ( + "bytes" "os" "path/filepath" "testing" @@ -12,93 +13,128 @@ import ( "kcl-lang.io/kpm/pkg/utils" ) -func testAddWithModSpec(t *testing.T) { +func TestAddWithModSpec(t *testing.T) { tests := []struct { name string pkgSubPath string sourceUrl string + msg string }{ { name: "TestAddOciWithModSpec", pkgSubPath: "oci", sourceUrl: "oci://ghcr.io/kcl-lang/helloworld?tag=0.1.4&mod=subhelloworld:0.0.1", + msg: "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'" + + "adding dependency 'subhelloworld'" + + "add dependency 'subhelloworld:0.0.1' successfully", }, { name: "TestAddGitWithModSpec", pkgSubPath: "git", sourceUrl: "git://github.com/kcl-lang/flask-demo-kcl-manifests.git?commit=8308200&mod=cc:0.0.1", + msg: "cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit '8308200'" + + "adding dependency 'cc'" + + "add dependency 'cc:0.0.1' successfully", + }, + { + name: "TestAddGitWithModSpec", + pkgSubPath: "git_mod_0", + sourceUrl: "git://github.com/kcl-lang/flask-demo-kcl-manifests.git?commit=8308200&mod=cc", + msg: "cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit '8308200'" + + "adding dependency 'cc'" + + "add dependency 'cc:0.0.1' successfully", + }, + { + name: "TestAddGitWithoutModFileWithModSpec", + pkgSubPath: "git_mod_1", + sourceUrl: "git://github.com/kcl-lang/flask-demo-kcl-manifests.git?commit=5ab0fff&mod=cc", + msg: "cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit '5ab0fff'" + + "adding dependency 'cc'" + + "add dependency 'cc:0.0.1' successfully", }, { name: "TestAddLocalWithModSpec", pkgSubPath: filepath.Join("local", "pkg"), sourceUrl: "../dep?mod=sub:0.0.1", + msg: "adding dependency 'sub'" + + "add dependency 'sub:0.0.1' successfully", }, { name: "TestAddOciWithEmptyVersion", pkgSubPath: "empty_version", sourceUrl: "oci://ghcr.io/kcl-lang/helloworld?tag=0.1.4&mod=subhelloworld", + msg: "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'" + + "adding dependency 'subhelloworld'" + + "add dependency 'subhelloworld:0.0.1' successfully", }, { name: "TestAddOciWithNoSpec", pkgSubPath: "no_spec", sourceUrl: "oci://ghcr.io/kcl-lang/helloworld?tag=0.1.4", + msg: "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'" + + "adding dependency 'helloworld'" + + "add dependency 'helloworld:0.1.4' successfully", }, { name: "TestAddOciWithNoTag", pkgSubPath: "no_oci_ref", sourceUrl: "oci://ghcr.io/kcl-lang/helloworld", + msg: "the lastest version '0.1.4' will be downloaded" + + "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'" + + "adding dependency 'helloworld'" + + "add dependency 'helloworld:0.1.4' successfully", }, { name: "TestAddGitWithNoTag", pkgSubPath: "no_git_ref", sourceUrl: "git://github.com/kcl-lang/flask-demo-kcl-manifests.git", + msg: "the lastest version 'ade147b' will be downloaded" + + "cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit 'ade147b'" + + "adding dependency 'flask_manifests'" + + "add dependency 'flask_manifests:0.0.1' successfully", }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - testDir := getTestDir("add_with_mod_spec") - pkgPath := filepath.Join(testDir, tt.pkgSubPath) - - modbkPath := filepath.Join(pkgPath, "kcl.mod.bk") - modPath := filepath.Join(pkgPath, "kcl.mod") - modExpect := filepath.Join(pkgPath, "kcl.mod.expect") - lockbkPath := filepath.Join(pkgPath, "kcl.mod.lock.bk") - lockPath := filepath.Join(pkgPath, "kcl.mod.lock") - lockExpect := filepath.Join(pkgPath, "kcl.mod.lock.expect") - - err := copy.Copy(modbkPath, modPath) - if err != nil { - t.Fatal(err) - } + testDir := getTestDir("add_with_mod_spec") + pkgPath := filepath.Join(testDir, tt.pkgSubPath) - err = copy.Copy(lockbkPath, lockPath) + modbkPath := filepath.Join(pkgPath, "kcl.mod.bk") + modPath := filepath.Join(pkgPath, "kcl.mod") + modExpect := filepath.Join(pkgPath, "kcl.mod.expect") + lockbkPath := filepath.Join(pkgPath, "kcl.mod.lock.bk") + lockPath := filepath.Join(pkgPath, "kcl.mod.lock") + lockExpect := filepath.Join(pkgPath, "kcl.mod.lock.expect") + + err := copy.Copy(modbkPath, modPath) + if err != nil { + t.Fatal(err) + } + + err = copy.Copy(lockbkPath, lockPath) + if err != nil { + t.Fatal(err) + } + + defer func() { + // remove the copied files + err := os.RemoveAll(modPath) if err != nil { t.Fatal(err) } - - defer func() { - // remove the copied files - err := os.RemoveAll(modPath) - if err != nil { - t.Fatal(err) - } - err = os.RemoveAll(lockPath) - if err != nil { - t.Fatal(err) - } - }() - - kpmcli, err := NewKpmClient() + err = os.RemoveAll(lockPath) if err != nil { t.Fatal(err) } + }() + testFunc := func(t *testing.T, kpmcli *KpmClient) { + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) kpkg, err := pkg.LoadKclPkgWithOpts( pkg.WithPath(pkgPath), pkg.WithSettings(kpmcli.GetSettings()), ) - if err != nil { t.Fatal(err) } @@ -112,32 +148,36 @@ func testAddWithModSpec(t *testing.T) { t.Fatal(err) } - expectedMod, err := os.ReadFile(modExpect) - if err != nil { - t.Fatal(err) - } - gotMod, err := os.ReadFile(modPath) - if err != nil { - t.Fatal(err) - } + assert.Equal(t, utils.RmNewline(tt.msg), utils.RmNewline(buf.String())) + } - expectedLock, err := os.ReadFile(lockExpect) - if err != nil { - t.Fatal(err) - } + RunTestWithGlobalLockAndKpmCli(t, tt.name, testFunc) - gotLock, err := os.ReadFile(lockPath) - if err != nil { - t.Fatal(err) - } + expectedMod, err := os.ReadFile(modExpect) + if err != nil { + t.Fatal(err) + } + gotMod, err := os.ReadFile(modPath) + if err != nil { + t.Fatal(err) + } + + expectedLock, err := os.ReadFile(lockExpect) + if err != nil { + t.Fatal(err) + } - assert.Equal(t, utils.RmNewline(string(expectedMod)), utils.RmNewline(string(gotMod))) - assert.Equal(t, utils.RmNewline(string(expectedLock)), utils.RmNewline(string(gotLock))) - }) + gotLock, err := os.ReadFile(lockPath) + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, utils.RmNewline(string(expectedMod)), utils.RmNewline(string(gotMod))) + assert.Equal(t, utils.RmNewline(string(expectedLock)), utils.RmNewline(string(gotLock))) } } -func testAddRenameWithModSpec(t *testing.T) { +func TestAddRenameWithModSpec(t *testing.T) { testDir := getTestDir("add_with_mod_spec") pkgPath := filepath.Join(testDir, "rename_spec_only") @@ -170,33 +210,39 @@ func testAddRenameWithModSpec(t *testing.T) { } }() - kpmcli, err := NewKpmClient() - if err != nil { - t.Fatal(err) - } - - kpkg, err := pkg.LoadKclPkgWithOpts( - pkg.WithPath(pkgPath), - pkg.WithSettings(kpmcli.GetSettings()), - ) + testFunc := func(t *testing.T, kpmcli *KpmClient) { + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) + kpkg, err := pkg.LoadKclPkgWithOpts( + pkg.WithPath(pkgPath), + pkg.WithSettings(kpmcli.GetSettings()), + ) + if err != nil { + t.Fatal(err) + } - if err != nil { - t.Fatal(err) - } + err = kpmcli.Add( + WithAddKclPkg(kpkg), + WithAddModSpec(&downloader.ModSpec{ + Name: "helloworld", + Version: "0.1.2", + }), + WithAlias("newpkg"), + ) - err = kpmcli.Add( - WithAddKclPkg(kpkg), - WithAddModSpec(&downloader.ModSpec{ - Name: "helloworld", - Version: "0.1.2", - }), - WithAlias("newpkg"), - ) + if err != nil { + t.Fatal(err) + } - if err != nil { - t.Fatal(err) + assert.Equal(t, utils.RmNewline( + "downloading 'kcl-lang/helloworld:0.1.2' from 'ghcr.io/kcl-lang/helloworld:0.1.2'"+ + "adding dependency 'helloworld'"+ + "add dependency 'helloworld:0.1.2' successfully", + ), utils.RmNewline(buf.String())) } + RunTestWithGlobalLockAndKpmCli(t, "TestAddRenameWithModSpec", testFunc) + expectedMod, err := os.ReadFile(modExpect) if err != nil { t.Fatal(err) @@ -220,23 +266,34 @@ func testAddRenameWithModSpec(t *testing.T) { assert.Equal(t, utils.RmNewline(string(expectedLock)), utils.RmNewline(string(gotLock))) } -func testAddWithOnlyModSpec(t *testing.T) { +func TestAddWithOnlyModSpec(t *testing.T) { testCases := []struct { + name string testDir string pkgSubDir string + msg string modSpec *downloader.ModSpec }{ { + name: "TestAddWithOnlyModSpec", testDir: "add_with_mod_spec", pkgSubDir: "spec_only", + msg: "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'" + + "adding dependency 'helloworld'" + + "add dependency 'helloworld:0.1.4' successfully", modSpec: &downloader.ModSpec{ Name: "helloworld", Version: "0.1.4", }, }, { + name: "TestAddWithOnlyModSpecButNoVersion", testDir: "add_with_mod_spec", pkgSubDir: "spec_only_no_ver", + msg: "the lastest version '0.1.4' will be downloaded" + + "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'" + + "adding dependency 'helloworld'" + + "add dependency 'helloworld:0.1.4' successfully", modSpec: &downloader.ModSpec{ Name: "helloworld", }, @@ -276,29 +333,33 @@ func testAddWithOnlyModSpec(t *testing.T) { } }() - kpmcli, err := NewKpmClient() - if err != nil { - t.Fatal(err) - } + testFunc := func(t *testing.T, kpmcli *KpmClient) { + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) - kpkg, err := pkg.LoadKclPkgWithOpts( - pkg.WithPath(pkgPath), - pkg.WithSettings(kpmcli.GetSettings()), - ) + kpkg, err := pkg.LoadKclPkgWithOpts( + pkg.WithPath(pkgPath), + pkg.WithSettings(kpmcli.GetSettings()), + ) - if err != nil { - t.Fatal(err) - } + if err != nil { + t.Fatal(err) + } - err = kpmcli.Add( - WithAddKclPkg(kpkg), - WithAddModSpec(tc.modSpec), - ) + err = kpmcli.Add( + WithAddKclPkg(kpkg), + WithAddModSpec(tc.modSpec), + ) - if err != nil { - t.Fatal(err) + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, utils.RmNewline(tc.msg), utils.RmNewline(buf.String())) } + RunTestWithGlobalLockAndKpmCli(t, tc.name, testFunc) + expectedMod, err := os.ReadFile(modExpect) if err != nil { t.Fatal(err) @@ -323,7 +384,7 @@ func testAddWithOnlyModSpec(t *testing.T) { } } -func testAddRenameWithNoSpec(t *testing.T) { +func TestAddRenameWithNoSpec(t *testing.T) { testDir := getTestDir("add_with_mod_spec") pkgPath := filepath.Join(testDir, "rename_no_spec") @@ -356,37 +417,48 @@ func testAddRenameWithNoSpec(t *testing.T) { } }() - kpmcli, err := NewKpmClient() - if err != nil { - t.Fatal(err) - } + testFunc := func(t *testing.T, kpmcli *KpmClient) { - kpkg, err := pkg.LoadKclPkgWithOpts( - pkg.WithPath(pkgPath), - pkg.WithSettings(kpmcli.GetSettings()), - ) + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) - if err != nil { - t.Fatal(err) - } + kpkg, err := pkg.LoadKclPkgWithOpts( + pkg.WithPath(pkgPath), + pkg.WithSettings(kpmcli.GetSettings()), + ) - err = kpmcli.Add( - WithAddKclPkg(kpkg), - WithAddSource(&downloader.Source{ - ModSpec: &downloader.ModSpec{ - Alias: "newpkg", - }, - Oci: &downloader.Oci{ - Reg: "ghcr.io", - Repo: "kcl-lang/helloworld", - }, - }), - ) + if err != nil { + t.Fatal(err) + } - if err != nil { - t.Fatal(err) + err = kpmcli.Add( + WithAddKclPkg(kpkg), + WithAddSource(&downloader.Source{ + ModSpec: &downloader.ModSpec{ + Alias: "newpkg", + }, + Oci: &downloader.Oci{ + Reg: "ghcr.io", + Repo: "kcl-lang/helloworld", + }, + }), + ) + + assert.Equal(t, + "the lastest version '0.1.4' will be downloaded"+ + "downloading 'kcl-lang/helloworld:0.1.4' from 'ghcr.io/kcl-lang/helloworld:0.1.4'"+ + "adding dependency 'helloworld'"+ + "add dependency 'helloworld:0.1.4' successfully", + utils.RmNewline(buf.String()), + ) + + if err != nil { + t.Fatal(err) + } } + RunTestWithGlobalLockAndKpmCli(t, "TestAddRenameWithNoSpec", testFunc) + expectedMod, err := os.ReadFile(modExpect) if err != nil { t.Fatal(err) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index f7520727..2abb601a 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -27,7 +27,6 @@ import ( "kcl-lang.io/kcl-go/pkg/kcl" "kcl-lang.io/kpm/pkg/downloader" "kcl-lang.io/kpm/pkg/env" - "kcl-lang.io/kpm/pkg/features" "kcl-lang.io/kpm/pkg/opt" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" @@ -36,25 +35,6 @@ import ( "kcl-lang.io/kpm/pkg/utils" ) -const testDataDir = "test_data" - -func getTestDir(subDir string) string { - pwd, _ := os.Getwd() - testDir := filepath.Join(pwd, testDataDir) - testDir = filepath.Join(testDir, subDir) - - return testDir -} - -func initTestDir(subDir string) string { - testDir := getTestDir(subDir) - // clean the test data - _ = os.RemoveAll(testDir) - _ = os.Mkdir(testDir, 0755) - - return testDir -} - func TestWithGlobalLock(t *testing.T) { test.RunTestWithGlobalLock(t, "TestUpdateWithKclMod", testUpdateWithKclMod) test.RunTestWithGlobalLock(t, "TestUpdateWithKclModlock", testUpdateWithKclModlock) @@ -83,7 +63,6 @@ func TestWithGlobalLock(t *testing.T) { test.RunTestWithGlobalLock(t, "TestDownloadGitWithPackage", testDownloadGitWithPackage) test.RunTestWithGlobalLock(t, "TestModandLockFilesWithGitPackageDownload", testModandLockFilesWithGitPackageDownload) test.RunTestWithGlobalLock(t, "TestDependencyGraph", testDependencyGraph) - test.RunTestWithGlobalLock(t, "TestAddWithModSpec", testAddWithModSpec) test.RunTestWithGlobalLock(t, "TestRunRemoteWithArgsInvalid", testRunRemoteWithArgsInvalid) test.RunTestWithGlobalLock(t, "TestRunRemoteWithArgs", testRunRemoteWithArgs) test.RunTestWithGlobalLock(t, "TestRunWithNoSumCheck", testRunWithGitPackage) @@ -93,18 +72,9 @@ func TestWithGlobalLock(t *testing.T) { test.RunTestWithGlobalLock(t, "TestPull", testPull) test.RunTestWithGlobalLock(t, "TestPullWithInsecureSkipTLSverify", testPullWithInsecureSkipTLSverify) test.RunTestWithGlobalLock(t, "TestPullWithModSpec", testPullWithModSpec) - test.RunTestWithGlobalLock(t, "testAddWithOnlyModSpec", testAddWithOnlyModSpec) - test.RunTestWithGlobalLock(t, "testAddRenameWithModSpec", testAddRenameWithModSpec) - test.RunTestWithGlobalLock(t, "testAddRenameWithNoSpec", testAddRenameWithNoSpec) test.RunTestWithGlobalLock(t, "testPullWithOnlySpec", testPullWithOnlySpec) test.RunTestWithGlobalLock(t, "TestRunWithModSpecVersion", testRunWithModSpecVersion) test.RunTestWithGlobalLock(t, "TestGraph", testGraph) - - features.Enable(features.SupportNewStorage) - test.RunTestWithGlobalLock(t, "testAddWithModSpec", testAddWithModSpec) - test.RunTestWithGlobalLock(t, "testAddWithOnlyModSpec", testAddWithOnlyModSpec) - test.RunTestWithGlobalLock(t, "testAddRenameWithModSpec", testAddRenameWithModSpec) - test.RunTestWithGlobalLock(t, "testAddRenameWithNoSpec", testAddRenameWithNoSpec) } // TestDownloadOci test download from oci registry. diff --git a/pkg/client/graph_test.go b/pkg/client/graph_test.go index 3f3891e8..af9a5963 100644 --- a/pkg/client/graph_test.go +++ b/pkg/client/graph_test.go @@ -4,8 +4,8 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/assert" "golang.org/x/mod/module" - "gotest.tools/v3/assert" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/utils" ) @@ -43,5 +43,7 @@ func testGraph(t *testing.T) { t.Fatalf("failed to display graph: %v", err) } - assert.Equal(t, utils.RmNewline(graStr), "pkg@0.0.1 dep@0.0.1pkg@0.0.1 helloworld@0.1.4dep@0.0.1 helloworld@0.1.4") + assert.Contains(t, utils.RmNewline(graStr), "pkg@0.0.1 dep@0.0.1") + assert.Contains(t, utils.RmNewline(graStr), "pkg@0.0.1 helloworld@0.1.4") + assert.Contains(t, utils.RmNewline(graStr), "dep@0.0.1 helloworld@0.1.4") } diff --git a/pkg/client/test.go b/pkg/client/test.go new file mode 100644 index 00000000..712c0eef --- /dev/null +++ b/pkg/client/test.go @@ -0,0 +1,60 @@ +package client + +import ( + "fmt" + "os" + "path/filepath" + "testing" +) + +const testDataDir = "test_data" + +func getTestDir(subDir string) string { + pwd, _ := os.Getwd() + testDir := filepath.Join(pwd, testDataDir) + testDir = filepath.Join(testDir, subDir) + + return testDir +} + +func initTestDir(subDir string) string { + testDir := getTestDir(subDir) + // clean the test data + _ = os.RemoveAll(testDir) + _ = os.Mkdir(testDir, 0755) + + return testDir +} + +// Use a global variable to store the kpmcli instance. +func RunTestWithGlobalLockAndKpmCli(t *testing.T, name string, testFunc func(t *testing.T, kpmcli *KpmClient)) { + t.Run(name, func(t *testing.T) { + kpmcli, err := NewKpmClient() + if err != nil { + t.Errorf("Error acquiring lock: %v", err) + } + err = kpmcli.AcquirePackageCacheLock() + if err != nil { + t.Errorf("Error acquiring lock: %v", err) + } + + defer func() { + err = kpmcli.ReleasePackageCacheLock() + if err != nil { + t.Errorf("Error acquiring lock: %v", err) + } + }() + + // create a tmp dir as kpm home for test + tmpDir, err := os.MkdirTemp("", "") + if err != nil { + t.Errorf("Error acquiring lock: %v", err) + } + // clean the temp dir. + defer os.RemoveAll(tmpDir) + kpmcli.SetHomePath(tmpDir) + + testFunc(t, kpmcli) + fmt.Printf("%s completed\n", name) + }) +} diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.bk b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.bk new file mode 100644 index 00000000..c894b72b --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.bk @@ -0,0 +1,4 @@ +[package] +name = "git" +edition = "v0.10.0" +version = "0.0.1" diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.expect b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.expect new file mode 100644 index 00000000..0465a74f --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.expect @@ -0,0 +1,7 @@ +[package] +name = "git" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "8308200", version = "0.0.1" } diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.lock.bk b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.lock.bk new file mode 100644 index 00000000..e69de29b diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.lock.expect b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.lock.expect new file mode 100644 index 00000000..6d55b3b1 --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_0/kcl.mod.lock.expect @@ -0,0 +1,7 @@ +[dependencies] + [dependencies.cc] + name = "cc" + full_name = "cc_0.0.1" + version = "0.0.1" + url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" + commit = "8308200" diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_0/main.k b/pkg/client/test_data/add_with_mod_spec/git_mod_0/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_0/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.bk b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.bk new file mode 100644 index 00000000..c894b72b --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.bk @@ -0,0 +1,4 @@ +[package] +name = "git" +edition = "v0.10.0" +version = "0.0.1" diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.expect b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.expect new file mode 100644 index 00000000..d378a02f --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.expect @@ -0,0 +1,7 @@ +[package] +name = "git" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "5ab0fff", version = "0.0.1" } diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.lock.bk b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.lock.bk new file mode 100644 index 00000000..e69de29b diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.lock.expect b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.lock.expect new file mode 100644 index 00000000..c3251325 --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_1/kcl.mod.lock.expect @@ -0,0 +1,7 @@ +[dependencies] + [dependencies.cc] + name = "cc" + full_name = "cc_0.0.1" + version = "0.0.1" + url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" + commit = "5ab0fff" diff --git a/pkg/client/test_data/add_with_mod_spec/git_mod_1/main.k b/pkg/client/test_data/add_with_mod_spec/git_mod_1/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/add_with_mod_spec/git_mod_1/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index 7d63cade..52dceba1 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -275,7 +275,7 @@ func (d *DepDownloader) Download(opts *DownloadOptions) error { localPath := opts.LocalPath cacheFullPath := opts.CachePath if ok, err := features.Enabled(features.SupportNewStorage); err == nil && !ok && opts.EnableCache { - if utils.DirExists(cacheFullPath) && utils.DirExists(filepath.Join(cacheFullPath, constants.KCL_MOD)) && + if utils.DirExists(cacheFullPath) && // If the version in modspec is empty, meanings the latest version is needed. // The latest version should be requested first and the cache should be updated. ((opts.Source.ModSpec != nil && opts.Source.ModSpec.Version != "") || opts.Source.ModSpec == nil) { diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index 212302c5..b05b6e74 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -571,7 +571,7 @@ func ParseOpt(opt *opt.RegistryOptions) (*Dependency, error) { Version: opt.Registry.Tag, Name: opt.Registry.Ref, }, - Oci: &ociSource, + Oci: &ociSource, }, Version: opt.Registry.Tag, }, nil diff --git a/pkg/package/test_data/test_rename_pkg/kcl.mod.lock b/pkg/package/test_data/test_rename_pkg/kcl.mod.lock new file mode 100644 index 00000000..fe419bb8 --- /dev/null +++ b/pkg/package/test_data/test_rename_pkg/kcl.mod.lock @@ -0,0 +1,8 @@ +[dependencies] + [dependencies.newpkg] + name = "newpkg" + full_name = "newpkg_0.0.1" + version = "0.0.1" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.4" diff --git a/pkg/visitor/visitor.go b/pkg/visitor/visitor.go index 23f13c60..fbe40760 100644 --- a/pkg/visitor/visitor.go +++ b/pkg/visitor/visitor.go @@ -222,13 +222,6 @@ func (rv *RemoteVisitor) Visit(s *downloader.Source, v visitFunc) error { defer os.RemoveAll(tmpDir) } - if !utils.DirExists(modFullPath) { - err := os.MkdirAll(modFullPath, 0755) - if err != nil { - return err - } - } - credCli, err = downloader.LoadCredentialFile(rv.Settings.CredentialsFile) if err != nil { return err