From 2847a4af6ff90f8163c6af3848edb4e499521bba Mon Sep 17 00:00:00 2001 From: zongz Date: Tue, 26 Mar 2024 20:53:01 +0800 Subject: [PATCH 1/4] fix: fix missing version when add dependencies from local path Signed-off-by: zongz --- pkg/client/client.go | 29 +++++----- pkg/client/client_test.go | 56 ++++++++++++++++++- .../expect/dep_pkg/kcl.mod | 5 ++ .../expect/dep_pkg/kcl.mod.lock | 0 .../add_with_local_path/expect/dep_pkg/main.k | 1 + .../add_with_local_path/expect/pkg/kcl.mod | 8 +++ .../expect/pkg/kcl.mod.lock | 15 +++++ .../add_with_local_path/expect/pkg/main.k | 1 + .../add_with_local_path/init/dep_pkg/kcl.mod | 5 ++ .../init/dep_pkg/kcl.mod.lock | 0 .../add_with_local_path/init/dep_pkg/main.k | 1 + .../add_with_local_path/init/pkg/kcl.mod | 7 +++ .../add_with_local_path/init/pkg/kcl.mod.lock | 7 +++ .../add_with_local_path/init/pkg/main.k | 1 + pkg/package/modfile.go | 14 ++++- 15 files changed, 132 insertions(+), 18 deletions(-) create mode 100644 pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod create mode 100644 pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod.lock create mode 100644 pkg/client/test_data/add_with_local_path/expect/dep_pkg/main.k create mode 100644 pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod create mode 100644 pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock create mode 100644 pkg/client/test_data/add_with_local_path/expect/pkg/main.k create mode 100644 pkg/client/test_data/add_with_local_path/init/dep_pkg/kcl.mod create mode 100644 pkg/client/test_data/add_with_local_path/init/dep_pkg/kcl.mod.lock create mode 100644 pkg/client/test_data/add_with_local_path/init/dep_pkg/main.k create mode 100644 pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod create mode 100644 pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod.lock create mode 100644 pkg/client/test_data/add_with_local_path/init/pkg/main.k diff --git a/pkg/client/client.go b/pkg/client/client.go index b762fcc0..28b97c48 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -714,7 +714,7 @@ func (c *KpmClient) VendorDeps(kclPkg *pkg.KclPkg) error { } // FillDepInfo will fill registry information for a dependency. -func (c *KpmClient) FillDepInfo(dep *pkg.Dependency) error { +func (c *KpmClient) FillDepInfo(dep *pkg.Dependency, homepath string) error { if dep.Source.Local != nil { dep.LocalFullPath = dep.Source.Local.Path return nil @@ -753,7 +753,7 @@ func (c *KpmClient) FillDepInfo(dep *pkg.Dependency) error { // FillDependenciesInfo will fill registry information for all dependencies in a kcl.mod. func (c *KpmClient) FillDependenciesInfo(modFile *pkg.ModFile) error { for k, v := range modFile.Deps { - err := c.FillDepInfo(&v) + err := c.FillDepInfo(&v, modFile.HomePath) if err != nil { return err } @@ -763,7 +763,7 @@ func (c *KpmClient) FillDependenciesInfo(modFile *pkg.ModFile) error { } // Download will download the dependency to the local path. -func (c *KpmClient) Download(dep *pkg.Dependency, localPath string) (*pkg.Dependency, error) { +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) if err != nil { @@ -788,12 +788,11 @@ func (c *KpmClient) Download(dep *pkg.Dependency, localPath string) (*pkg.Depend } if dep.Source.Oci != nil { - pkg, err := c.DownloadPkgFromOci(dep.Source.Oci, localPath) + kpkg, err := c.DownloadPkgFromOci(dep.Source.Oci, localPath) if err != nil { return nil, err } - dep.Version = pkg.GetPkgVersion() - dep.LocalFullPath = pkg.HomePath + dep.FromKclPkg(kpkg) // Creating symbolic links in a global cache is not an optimal solution. // This allows kclvm to locate the package by default. // This feature is unstable and will be removed soon. @@ -801,11 +800,14 @@ func (c *KpmClient) Download(dep *pkg.Dependency, localPath string) (*pkg.Depend if err != nil { return nil, err } - dep.FullName = pkg.GetPkgFullName() } if dep.Source.Local != nil { - dep.LocalFullPath = dep.Source.Local.Path + kpkg, err := pkg.FindFirstKclPkgFrom(dep.GetLocalFullPath(homePath)) + if err != nil { + return nil, err + } + dep.FromKclPkg(kpkg) } var err error @@ -1202,7 +1204,7 @@ func (c *KpmClient) InitGraphAndDownloadDeps(kclPkg *pkg.KclPkg) (*pkg.Dependenc return nil, nil, err } - changedDeps, err := c.downloadDeps(kclPkg.ModFile.Dependencies, kclPkg.Dependencies, depGraph, root) + changedDeps, err := c.downloadDeps(kclPkg.ModFile.Dependencies, kclPkg.Dependencies, depGraph, kclPkg.HomePath, root) if err != nil { return nil, nil, err } @@ -1226,7 +1228,7 @@ func (c *KpmClient) dependencyExists(dep *pkg.Dependency, lockDeps *pkg.Dependen if !c.noSumCheck && present { // If the dependent package does not exist locally, then method 'check' will return false. if c.noSumCheck || check(lockDep, filepath.Join(c.homePath, dep.FullName)) { - return dep + return &lockDep } } @@ -1234,7 +1236,8 @@ func (c *KpmClient) dependencyExists(dep *pkg.Dependency, lockDeps *pkg.Dependen } // downloadDeps will download all the dependencies of the current kcl package. -func (c *KpmClient) downloadDeps(deps pkg.Dependencies, lockDeps pkg.Dependencies, depGraph graph.Graph[string, string], parent string) (*pkg.Dependencies, error) { +func (c *KpmClient) downloadDeps(deps pkg.Dependencies, lockDeps pkg.Dependencies, depGraph graph.Graph[string, string], pkghome, parent string) (*pkg.Dependencies, error) { + newDeps := pkg.Dependencies{ Deps: make(map[string]pkg.Dependency), } @@ -1260,7 +1263,7 @@ func (c *KpmClient) downloadDeps(deps pkg.Dependencies, lockDeps pkg.Dependencie os.RemoveAll(dir) // download dependencies - lockedDep, err := c.Download(&d, dir) + lockedDep, err := c.Download(&d, pkghome, dir) if err != nil { return nil, err } @@ -1325,7 +1328,7 @@ func (c *KpmClient) downloadDeps(deps pkg.Dependencies, lockDeps pkg.Dependencie } // Download the dependencies. - nested, err := c.downloadDeps(deppkg.ModFile.Dependencies, lockDeps, depGraph, source) + nested, err := c.downloadDeps(deppkg.ModFile.Dependencies, lockDeps, depGraph, deppkg.HomePath, source) if err != nil { return nil, err } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 0f759e36..6173b3aa 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -70,7 +70,7 @@ func TestDownloadOci(t *testing.T) { } kpmcli, err := NewKpmClient() assert.Equal(t, err, nil) - dep, err := kpmcli.Download(&depFromOci, testPath) + dep, err := kpmcli.Download(&depFromOci, "", testPath) assert.Equal(t, err, nil) assert.Equal(t, dep.Name, "k8s") assert.Equal(t, dep.FullName, "k8s_1.27") @@ -131,7 +131,7 @@ func TestDownloadLatestOci(t *testing.T) { } kpmcli, err := NewKpmClient() assert.Equal(t, err, nil) - dep, err := kpmcli.Download(&depFromOci, testPath) + dep, err := kpmcli.Download(&depFromOci, "", testPath) assert.Equal(t, err, nil) assert.Equal(t, dep.Name, "helloworld") assert.Equal(t, dep.FullName, "helloworld_0.1.1") @@ -227,7 +227,7 @@ func TestCyclicDependency(t *testing.T) { _, _, err = kpmcli.InitGraphAndDownloadDeps(kclPkg) assert.Equal(t, err, reporter.NewErrorEvent( - reporter.CircularDependencyExist, nil, "adding bbb as a dependency results in a cycle", + reporter.CircularDependencyExist, nil, "adding aaa@0.0.1 as a dependency results in a cycle", )) err = os.Chdir(currentDir) @@ -1315,3 +1315,53 @@ func TestLoadPkgFormOci(t *testing.T) { assert.Equal(t, kclpkg.GetPkgName(), tc.Name) } } + +func TestAddWithLocalPath(t *testing.T) { + + testpath := getTestDir("add_with_local_path") + + initpath := filepath.Join(testpath, "init") + tmppath := filepath.Join(testpath, "tmp") + expectpath := filepath.Join(testpath, "expect") + + defer func() { + err := os.RemoveAll(tmppath) + assert.Equal(t, err, nil) + }() + + err := copy.Copy(initpath, tmppath) + assert.Equal(t, err, nil) + + kpmcli, err := NewKpmClient() + assert.Equal(t, err, nil) + kpmcli.SetLogWriter(nil) + + tmpPkgPath := filepath.Join(tmppath, "pkg") + opts := opt.AddOptions{ + LocalPath: tmpPkgPath, + RegistryOpts: opt.RegistryOptions{ + Oci: &opt.OciOptions{ + Reg: "ghcr.io", + Repo: "kcl-lang", + PkgName: "helloworld", + Tag: "0.1.1", + }, + }, + } + + kclPkg, err := kpmcli.LoadPkgFromPath(tmpPkgPath) + assert.Equal(t, err, nil) + + _, err = kpmcli.AddDepWithOpts(kclPkg, &opts) + assert.Equal(t, err, nil) + + gotpkg, err := kpmcli.LoadPkgFromPath(tmpPkgPath) + assert.Equal(t, err, nil) + expectpath = filepath.Join(expectpath, "pkg") + expectpkg, err := kpmcli.LoadPkgFromPath(expectpath) + assert.Equal(t, err, nil) + + assert.Equal(t, len(gotpkg.Dependencies.Deps), len(expectpkg.Dependencies.Deps)) + assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].FullName, expectpkg.Dependencies.Deps["dep_pkg"].FullName) + assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].Version, expectpkg.Dependencies.Deps["dep_pkg"].Version) +} diff --git a/pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod b/pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod new file mode 100644 index 00000000..9f3a6681 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "dep_pkg" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod.lock b/pkg/client/test_data/add_with_local_path/expect/dep_pkg/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/pkg/client/test_data/add_with_local_path/expect/dep_pkg/main.k b/pkg/client/test_data/add_with_local_path/expect/dep_pkg/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/expect/dep_pkg/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_local_path/expect/pkg/kcl.mod b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod new file mode 100644 index 00000000..778e75b0 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod @@ -0,0 +1,8 @@ +[package] +name = "pkg" +edition = "v0.8.0" +version = "0.0.1" + +[dependencies] +dep_pkg = { path = "../dep_pkg" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.1" } diff --git a/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock new file mode 100644 index 00000000..7a5d3c5b --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock @@ -0,0 +1,15 @@ +[dependencies] + [dependencies.dep_pkg] + name = "dep_pkg" + full_name = "dep_pkg_0.0.1" + version = "0.0.1" + sum = "C3TjaZJVdt4G8TtbiCxTUO/zAlf7fWJTAvs/CDMnlxY=" + path = "../dep_pkg" + [dependencies.helloworld] + name = "helloworld" + full_name = "helloworld_0.1.1" + version = "0.1.1" + sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.1" diff --git a/pkg/client/test_data/add_with_local_path/expect/pkg/main.k b/pkg/client/test_data/add_with_local_path/expect/pkg/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/expect/pkg/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_local_path/init/dep_pkg/kcl.mod b/pkg/client/test_data/add_with_local_path/init/dep_pkg/kcl.mod new file mode 100644 index 00000000..9f3a6681 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/init/dep_pkg/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "dep_pkg" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/pkg/client/test_data/add_with_local_path/init/dep_pkg/kcl.mod.lock b/pkg/client/test_data/add_with_local_path/init/dep_pkg/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/pkg/client/test_data/add_with_local_path/init/dep_pkg/main.k b/pkg/client/test_data/add_with_local_path/init/dep_pkg/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/init/dep_pkg/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_local_path/init/pkg/kcl.mod b/pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod new file mode 100644 index 00000000..6d2aa19c --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "pkg" +edition = "v0.8.0" +version = "0.0.1" + +[dependencies] +dep_pkg = { path = "../dep_pkg" } diff --git a/pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod.lock b/pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod.lock new file mode 100644 index 00000000..0742661b --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/init/pkg/kcl.mod.lock @@ -0,0 +1,7 @@ +[dependencies] + [dependencies.dep_pkg] + name = "dep_pkg" + full_name = "dep_pkg_0.0.1" + version = "0.0.1" + sum = "C3TjaZJVdt4G8TtbiCxTUO/zAlf7fWJTAvs/CDMnlxY=" + path = "../dep_pkg" diff --git a/pkg/client/test_data/add_with_local_path/init/pkg/main.k b/pkg/client/test_data/add_with_local_path/init/pkg/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/add_with_local_path/init/pkg/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index 0509e486..d9c8d965 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -112,7 +112,7 @@ func (profile *Profile) GetEntries() []string { // FillDependenciesInfo will fill registry information for all dependencies in a kcl.mod. func (modFile *ModFile) FillDependenciesInfo() error { for k, v := range modFile.Deps { - err := v.FillDepInfo() + err := v.FillDepInfo(modFile.HomePath) if err != nil { return err } @@ -168,6 +168,13 @@ type Dependency struct { Source `json:"-"` } +func (d *Dependency) FromKclPkg(pkg *KclPkg) { + d.Name = pkg.GetPkgName() + d.FullName = pkg.GetPkgFullName() + d.Version = pkg.GetPkgVersion() + d.LocalFullPath = pkg.HomePath +} + // SetName will set the name and alias name of a dependency. func (d *Dependency) GetAliasName() string { return strings.ReplaceAll(d.Name, "-", "_") @@ -205,7 +212,7 @@ func (dep *Dependency) IsFromLocal() bool { } // FillDepInfo will fill registry information for a dependency. -func (dep *Dependency) FillDepInfo() error { +func (dep *Dependency) FillDepInfo(homepath string) error { if dep.Source.Oci != nil { settings := settings.GetSettings() if settings.ErrorEvent != nil { @@ -220,6 +227,9 @@ func (dep *Dependency) FillDepInfo() error { dep.Source.Oci.Repo = urlpath } } + if dep.Source.Local != nil { + dep.LocalFullPath = dep.Source.Local.Path + } return nil } From d204d2ff7b98563f77e7b7fee6fc68e7fd18e010 Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 27 Mar 2024 10:26:19 +0800 Subject: [PATCH 2/4] fix: fix missing version in `kpm run` Signed-off-by: zongz --- pkg/client/client.go | 15 +++-- pkg/package/modfile.go | 6 +- .../test_suite.env | 2 + .../test_suite.input | 1 + .../test_suite.stderr | 0 .../test_suite.stdout | 66 +++++++++++++++++++ .../pkg1/kcl.mod | 8 +++ .../pkg1/kcl.mod.lock | 13 ++++ .../test_kpm_run_multi_local_path/pkg1/main.k | 3 + .../pkg2/kcl.mod | 7 ++ .../pkg2/kcl.mod.lock | 7 ++ .../test_kpm_run_multi_local_path/pkg2/main.k | 3 + .../pkg3/kcl.mod | 5 ++ .../pkg3/kcl.mod.lock | 0 .../test_kpm_run_multi_local_path/pkg3/main.k | 1 + 15 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.env create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.input create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stderr create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/main.k create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/main.k create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/main.k diff --git a/pkg/client/client.go b/pkg/client/client.go index 28b97c48..b43fc02f 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -221,13 +221,13 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro searchFullPath := filepath.Join(searchPath, d.FullName) if !update { if d.IsFromLocal() { - searchFullPath = d.GetLocalFullPath(kclPkg.HomePath) + depPkg, err := c.LoadPkgFromPath(d.GetLocalFullPath(kclPkg.HomePath)) + if err != nil { + return err + } + d.FromKclPkg(depPkg) } - - // Find it and update the local path of the dependency. - d.LocalFullPath = searchFullPath kclPkg.Dependencies.Deps[name] = d - } else { if utils.DirExists(searchFullPath) && (c.GetNoSumCheck() || utils.CheckPackageSum(d.Sum, searchFullPath)) { // Find it and update the local path of the dependency. @@ -241,6 +241,11 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro return reporter.NewErrorEvent(reporter.CalSumFailed, err, fmt.Sprintf("failed to calculate checksum for '%s' in '%s'", d.Name, searchFullPath)) } d.Sum = sum + depPkg, err := c.LoadPkgFromPath(d.GetLocalFullPath(kclPkg.HomePath)) + if err != nil { + return err + } + d.FromKclPkg(depPkg) kclPkg.Dependencies.Deps[name] = d } else { // Otherwise, re-vendor it. diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index d9c8d965..57391a9a 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -183,8 +183,12 @@ func (d *Dependency) GetAliasName() string { // WithTheSameVersion will check whether two dependencies have the same version. func (d Dependency) WithTheSameVersion(other Dependency) bool { - sameNameAndVersion := d.Name == other.Name && d.Version == other.Version + var sameVersion = true + if len(d.Version) != 0 && len(other.Version) != 0 { + sameVersion = d.Version == other.Version + } + sameNameAndVersion := d.Name == other.Name && sameVersion sameGitSrc := true if d.Source.Git != nil && other.Source.Git != nil { sameGitSrc = d.Source.Git.Url == other.Source.Git.Url && diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.input new file mode 100644 index 00000000..6e0e6d6f --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.input @@ -0,0 +1 @@ +kpm run /pkg1 \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout new file mode 100644 index 00000000..9e06157a --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout @@ -0,0 +1,66 @@ +helloworld: + workload: + containers: + nginx: + image: nginx:v1 + command: + - /bin/sh + - -c + - echo hi + args: + - /bin/sh + - -c + - echo hi + env: + env1: VALUE + env2: secret://sec-name/key + workingDir: /tmp + resources: + cpu: '2' + memory: 4Gi + readinessProbe: + probeHandler: + url: http://localhost:80 + initialDelaySeconds: 10 + secrets: + basic-auth: + type: basic + data: + username: admin + password: '******' + replicas: 2 + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + public: true +helloworldcollaset: + workload: + containers: + nginx: + image: nginx:v1 + command: + - /bin/sh + - -c + - echo hi + args: + - /bin/sh + - -c + - echo hi + workingDir: /tmp + ports: + - port: 80 + protocol: TCP + public: false + opsRule: + maxUnavailable: 30% +helloworldjob: + workload: + containers: + busybox: + image: busybox:1.28 + command: + - /bin/sh + - -c + - echo hello + schedule: 0 * * * * diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod new file mode 100644 index 00000000..46ac000a --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod @@ -0,0 +1,8 @@ +[package] +name = "pkg1" +edition = "v0.8.0" +version = "0.0.1" + +[dependencies] +pkg2 = { path = "../pkg2" } +pkg3 = { path = "../pkg3" } diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod.lock new file mode 100644 index 00000000..e59ebe56 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/kcl.mod.lock @@ -0,0 +1,13 @@ +[dependencies] + [dependencies.pkg2] + name = "pkg2" + full_name = "pkg2_0.0.1" + version = "0.0.1" + sum = "JbfIAXPJb3L6xX7hi/A5mrXzjpB8eFoKfEmJMdHsewY=" + path = "../pkg2" + [dependencies.pkg3] + name = "pkg3" + full_name = "pkg3_0.0.1" + version = "0.0.1" + sum = "T29gAv6K/tLithhP5jVHyurV5zRFui+i1ulyMt/ncnM=" + path = "../pkg3" diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/main.k b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/main.k new file mode 100644 index 00000000..93576dd4 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg1/main.k @@ -0,0 +1,3 @@ +import pkg2 + +The_first_kcl_program = pkg2.The_first_kcl_program \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod new file mode 100644 index 00000000..bd4c9bfe --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "pkg2" +edition = "v0.8.0" +version = "0.0.1" + +[dependencies] +pkg3 = { path = "../pkg3" } diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod.lock new file mode 100644 index 00000000..75909bea --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/kcl.mod.lock @@ -0,0 +1,7 @@ +[dependencies] + [dependencies.pkg3] + name = "pkg3" + full_name = "pkg3_0.0.1" + version = "0.0.1" + sum = "T29gAv6K/tLithhP5jVHyurV5zRFui+i1ulyMt/ncnM=" + path = "../pkg3" diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/main.k b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/main.k new file mode 100644 index 00000000..ec3e4ceb --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg2/main.k @@ -0,0 +1,3 @@ +import pkg3 + +The_first_kcl_program = pkg3.The_first_kcl_program \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod new file mode 100644 index 00000000..0f12aa22 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "pkg3" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/main.k b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path/pkg3/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file From f332ddf6426c98ee98176be411682316bbb8c370 Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 27 Mar 2024 10:29:40 +0800 Subject: [PATCH 3/4] fix: fix e2e test Signed-off-by: zongz --- .../test_suite.stdout | 67 +------------------ 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout index 9e06157a..f4059255 100644 --- a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path/test_suite.stdout @@ -1,66 +1 @@ -helloworld: - workload: - containers: - nginx: - image: nginx:v1 - command: - - /bin/sh - - -c - - echo hi - args: - - /bin/sh - - -c - - echo hi - env: - env1: VALUE - env2: secret://sec-name/key - workingDir: /tmp - resources: - cpu: '2' - memory: 4Gi - readinessProbe: - probeHandler: - url: http://localhost:80 - initialDelaySeconds: 10 - secrets: - basic-auth: - type: basic - data: - username: admin - password: '******' - replicas: 2 - ports: - - port: 80 - targetPort: 8080 - protocol: TCP - public: true -helloworldcollaset: - workload: - containers: - nginx: - image: nginx:v1 - command: - - /bin/sh - - -c - - echo hi - args: - - /bin/sh - - -c - - echo hi - workingDir: /tmp - ports: - - port: 80 - protocol: TCP - public: false - opsRule: - maxUnavailable: 30% -helloworldjob: - workload: - containers: - busybox: - image: busybox:1.28 - command: - - /bin/sh - - -c - - echo hello - schedule: 0 * * * * +The_first_kcl_program: Hello World! \ No newline at end of file From e8e2f8aba2c14da14f87d304db9ee634fa345238 Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 27 Mar 2024 10:44:18 +0800 Subject: [PATCH 4/4] fix: fix test case Signed-off-by: zongz --- pkg/client/client.go | 2 ++ pkg/client/test_data/resolve_metadata/kcl.mod.lock | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index b43fc02f..f4ec621b 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -226,6 +226,8 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro return err } d.FromKclPkg(depPkg) + } else { + d.LocalFullPath = searchFullPath } kclPkg.Dependencies.Deps[name] = d } else { diff --git a/pkg/client/test_data/resolve_metadata/kcl.mod.lock b/pkg/client/test_data/resolve_metadata/kcl.mod.lock index 2839f6fe..02b0b8e3 100644 --- a/pkg/client/test_data/resolve_metadata/kcl.mod.lock +++ b/pkg/client/test_data/resolve_metadata/kcl.mod.lock @@ -3,6 +3,6 @@ name = "konfig" full_name = "konfig_v0.0.1" version = "v0.0.1" - sum = "bcUvvcR21AFUE/Zf63wx6HkqzFYH1vihmE+SCd8OOCs=" + sum = "XFvHdBAoY/+qpJWmj8cjwOwZO8a3nX/7SE35cTxQOFU=" url = "https://github.com/awesome-kusion/konfig.git" git_tag = "v0.0.1"