Skip to content

Commit

Permalink
fix: rebase main
Browse files Browse the repository at this point in the history
Signed-off-by: zongzhe <[email protected]>
  • Loading branch information
zong-zhe committed Oct 14, 2024
1 parent 8fd77d8 commit 42c86e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 65 deletions.
63 changes: 0 additions & 63 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func TestWithGlobalLock(t *testing.T) {
test.RunTestWithGlobalLock(t, "TestResolveMetadataInJsonStr", testResolveMetadataInJsonStr)
test.RunTestWithGlobalLock(t, "testPackageCurrentPkgPath", testPackageCurrentPkgPath)
test.RunTestWithGlobalLock(t, "TestUpdateKclModAndLock", testUpdateKclModAndLock)
test.RunTestWithGlobalLock(t, "TestVendorDeps", testVendorDeps)
test.RunTestWithGlobalLock(t, "TestResolveDepsWithOnlyKclMod", testResolveDepsWithOnlyKclMod)
test.RunTestWithGlobalLock(t, "TestResolveDepsVendorMode", testResolveDepsVendorMode)
test.RunTestWithGlobalLock(t, "TestCompileWithEntryFile", testCompileWithEntryFile)
Expand Down Expand Up @@ -528,68 +527,6 @@ func testUpdateKclModAndLock(t *testing.T) {
}
}

func testVendorDeps(t *testing.T) {
testDir := getTestDir("resolve_deps")
kpm_home := filepath.Join(testDir, "kpm_home")
os.RemoveAll(filepath.Join(testDir, "my_kcl"))
kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1"))
kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2"))

depKcl1 := pkg.Dependency{
Name: "kcl1",
FullName: "kcl1",
Version: "0.0.1",
Sum: kcl1Sum,
}

depKcl2 := pkg.Dependency{
Name: "kcl2",
FullName: "kcl2",
Version: "0.0.1",
Sum: kcl2Sum,
}

mppTest := orderedmap.NewOrderedMap[string, pkg.Dependency]()
mppTest.Set("kcl1", depKcl1)
mppTest.Set("kcl2", depKcl2)

kclPkg := pkg.KclPkg{
ModFile: pkg.ModFile{
HomePath: filepath.Join(testDir, "my_kcl"),
// Whether the current package uses the vendor mode
// In the vendor mode, kpm will look for the package in the vendor subdirectory
// in the current package directory.
VendorMode: false,
Dependencies: pkg.Dependencies{
Deps: mppTest,
},
},
HomePath: filepath.Join(testDir, "my_kcl"),
// The dependencies in the current kcl package are the dependencies of kcl.mod.lock,
// not the dependencies in kcl.mod.
Dependencies: pkg.Dependencies{
Deps: mppTest,
},
}

mykclVendorPath := filepath.Join(filepath.Join(testDir, "my_kcl"), "vendor")
assert.Equal(t, utils.DirExists(mykclVendorPath), false)
kpmcli, err := NewKpmClient()
kpmcli.homePath = kpm_home
assert.Equal(t, err, nil)
err = kpmcli.VendorDeps(&kclPkg)
assert.Equal(t, err, nil)
assert.Equal(t, utils.DirExists(mykclVendorPath), true)
assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl1_0.0.1")), true)
assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl2_0.0.1")), true)

maps, err := kpmcli.ResolveDepsIntoMap(&kclPkg)
assert.Equal(t, err, nil)
assert.Equal(t, len(maps), 2)

os.RemoveAll(filepath.Join(testDir, "my_kcl"))
}

func testResolveDepsWithOnlyKclMod(t *testing.T) {
testDir := getTestDir("resolve_dep_with_kclmod")
assert.Equal(t, utils.DirExists(filepath.Join(testDir, "kcl.mod.lock")), false)
Expand Down
10 changes: 8 additions & 2 deletions pkg/client/vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"kcl-lang.io/kpm/pkg/downloader"
pkg "kcl-lang.io/kpm/pkg/package"
"kcl-lang.io/kpm/pkg/settings"
"kcl-lang.io/kpm/pkg/test"
"kcl-lang.io/kpm/pkg/utils"
)

func TestVendorDeps(t *testing.T) {
func testVendorDeps(t *testing.T) {
testDir := getTestDir("resolve_deps")
kpm_home := filepath.Join(testDir, "kpm_home")
os.RemoveAll(filepath.Join(testDir, "my_kcl"))
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestVendorDeps(t *testing.T) {
os.RemoveAll(filepath.Join(testDir, "my_kcl"))
}

func TestVendorWithMVS(t *testing.T) {
func testVendorWithMVS(t *testing.T) {
testDir := getTestDir("test_vendor")
pkgPath := filepath.Join(testDir, "pkg")
kPkg, err := pkg.LoadKclPkgWithOpts(
Expand All @@ -107,3 +108,8 @@ func TestVendorWithMVS(t *testing.T) {
assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "vendor", "helloworld_0.1.2")), true)
assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "vendor", "helloworld_0.1.1")), false)
}

func TestVendorWithGlobalLock(t *testing.T) {
test.RunTestWithGlobalLock(t, "TestVendorDeps", testVendorDeps)
test.RunTestWithGlobalLock(t, "TestVendorWithMVS", testVendorWithMVS)
}

0 comments on commit 42c86e3

Please sign in to comment.