Skip to content

Commit

Permalink
fix: fix test cases
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe committed Nov 29, 2024
1 parent 5586463 commit ade848d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
20 changes: 0 additions & 20 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,26 +946,6 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (*
return dep, nil
}

func (c *KpmClient) ValidateDependency(dep *pkg.Dependency) error {
if ok, err := features.Enabled(features.SupportModCheck); err == nil && ok {
tmpKclPkg := pkg.KclPkg{
HomePath: dep.LocalFullPath,
Dependencies: pkg.Dependencies{Deps: func() *orderedmap.OrderedMap[string, pkg.Dependency] {
m := orderedmap.NewOrderedMap[string, pkg.Dependency]()
m.Set(dep.Name, *dep)
return m
}()},
NoSumCheck: c.GetNoSumCheck(),
}

if err := c.ModChecker.Check(tmpKclPkg); err != nil {
return reporter.NewErrorEvent(reporter.InvalidKclPkg, err, fmt.Sprintf("%s package does not match the original kcl package", dep.FullName))
}
}

return nil
}

// DownloadFromGit will download the dependency from the git repository.
func (c *KpmClient) DownloadFromGit(dep *downloader.Git, localPath string) (string, error) {
var msg string
Expand Down
1 change: 1 addition & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,7 @@ func TestValidateDependency(t *testing.T) {
},
}
err = kpmcli.ValidateDependency(&dep1)
fmt.Printf("err: %v\n", err)
assert.Equal(t, err, nil)

dep2 := pkg.Dependency{
Expand Down
29 changes: 29 additions & 0 deletions pkg/client/deperated.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"os"
"path/filepath"

"github.com/elliotchance/orderedmap/v2"
"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kpm/pkg/downloader"
"kcl-lang.io/kpm/pkg/features"
"kcl-lang.io/kpm/pkg/git"
"kcl-lang.io/kpm/pkg/oci"
"kcl-lang.io/kpm/pkg/opt"
Expand All @@ -16,6 +18,33 @@ import (
"kcl-lang.io/kpm/pkg/utils"
)

// Deprecated: ValidateDependency is deprecated, use `Check` replaced.
func (c *KpmClient) ValidateDependency(dep *pkg.Dependency) error {
if ok, err := features.Enabled(features.SupportModCheck); err == nil && ok {
tmpKclPkg := pkg.KclPkg{
ModFile: pkg.ModFile{
Pkg: pkg.Package{
Name: dep.Name,
Version: dep.Version,
},
},
HomePath: dep.LocalFullPath,
Dependencies: pkg.Dependencies{Deps: func() *orderedmap.OrderedMap[string, pkg.Dependency] {
m := orderedmap.NewOrderedMap[string, pkg.Dependency]()
m.Set(dep.Name, *dep)
return m
}()},
NoSumCheck: c.GetNoSumCheck(),
}

if err := c.ModChecker.Check(tmpKclPkg); err != nil {
return reporter.NewErrorEvent(reporter.InvalidKclPkg, err, fmt.Sprintf("%s package does not match the original kcl package", dep.FullName))
}
}

return nil
}

// CompileWithOpts will compile the kcl program with the compile options.
// Deprecated: Use `Run` instead.
func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultList, error) {
Expand Down

0 comments on commit ade848d

Please sign in to comment.