Skip to content

Commit

Permalink
fix: fail unit test cases
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed May 11, 2024
1 parent f60d5bd commit 015ccfb
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 36 deletions.
23 changes: 11 additions & 12 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ func TestDownloadLatestOci(t *testing.T) {
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")
assert.Equal(t, dep.Version, "0.1.1")
assert.Equal(t, dep.Sum, "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=")
assert.Equal(t, dep.FullName, "helloworld_0.1.2")
assert.Equal(t, dep.Version, "0.1.2")
assert.Equal(t, dep.Sum, "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=")
assert.NotEqual(t, dep.Source.Oci, nil)
assert.Equal(t, dep.Source.Oci.Reg, "ghcr.io")
assert.Equal(t, dep.Source.Oci.Repo, "kcl-lang/helloworld")
assert.Equal(t, dep.Source.Oci.Tag, "0.1.1")
assert.Equal(t, dep.Source.Oci.Tag, "0.1.2")
assert.Equal(t, dep.LocalFullPath, testPath)
assert.Equal(t, err, nil)

// Check whether the tar downloaded by `kpm add` has been deleted.
assert.Equal(t, utils.DirExists(filepath.Join(testPath, "helloworld_0.1.1.tar")), false)
assert.Equal(t, utils.DirExists(filepath.Join(testPath, "helloworld_0.1.2.tar")), false)

assert.Equal(t, utils.DirExists(filepath.Join(getTestDir("download"), "helloworld")), false)
}
Expand Down Expand Up @@ -216,13 +216,12 @@ func TestParseKclModFile(t *testing.T) {
modFilePath := filepath.Join(testDir, "kcl.mod")

// Write modFileContent to modFilePath
modFileContent := `
[dependencies]
teleport = "0.1.0"
rabbitmq = "0.0.1"
gitdep = { git = "git://example.com/repo.git", tag = "v1.0.0" }
localdep = { path = "/path/to/local/dependency" }
`
modFileContent := `[dependencies]
teleport = "0.1.0"
rabbitmq = "0.0.1"
gitdep = { git = "git://example.com/repo.git", tag = "v1.0.0" }
localdep = { path = "/path/to/local/dependency" }
`

err = os.WriteFile(modFilePath, []byte(modFileContent), 0644)
assert.Nil(t, err, "error writing mod file")
Expand Down
9 changes: 9 additions & 0 deletions pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[dependencies]
[dependencies.kcl1]
name = "kcl1"
full_name = "kcl1"
sum = "c5bjxiHbwJqWCdBwXLOr9MydCTis3nJotrOzozkPsKo="
[dependencies.kcl2]
name = "kcl2"
full_name = "kcl2"
sum = "OiA7IJfhi9bLp3d+Phc6ncgWE8XwpXqkGvhF5BOpf34="
2 changes: 1 addition & 1 deletion pkg/client/test_data/test_data_add_deps/kcl.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ edition = "v0.8.0"
version = "0.0.1"

[dependencies]
oci_name = "test_tag"
oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" }
name = { git = "test_url", tag = "test_tag" }
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_flags.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// This file provides all the flags in the kpm cli.
//
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func KpmGraph(c *cli.Context, kpmcli *client.KpmClient) error {
}

// print the dependency graph to stdout.
root := fmt.Sprintf("%s@%s", kclPkg.GetPkgName(), kclPkg.GetPkgVersion())
root := fmt.Sprintf("%s@%s", kclPkg.GetPkgName(), kclPkg.GetPkgVersion())
err = graph.BFS(depGraph, root, func(source string) bool {
for target := range adjMap[source] {
reporter.ReportMsgTo(
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_import.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_init.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_login.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_logout.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_pkg.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_pull.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_push_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cmd_update.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package cmd
Expand Down
18 changes: 12 additions & 6 deletions pkg/package/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ const (

// 'Package' is the kcl package section of 'kcl.mod'.
type Package struct {
Name string `toml:"name,omitempty"` // kcl package name
Edition string `toml:"edition,omitempty"` // kcl compiler version
Version string `toml:"version,omitempty"` // kcl package version
Description string `toml:"description,omitempty"` // kcl package description
Include []string `toml:"include,omitempty"` // kcl package include
Exclude []string `toml:"exclude,omitempty"` // kcl package exclude
// The name of the package.
Name string `toml:"name,omitempty"`
// The kcl compiler version
Edition string `toml:"edition,omitempty"`
// The version of the package.
Version string `toml:"version,omitempty"`
// Description denotes the description of the package.
Description string `toml:"description,omitempty"` // kcl package description
// Exclude denote the files to include when publishing.
Include []string `toml:"include,omitempty"`
// Exclude denote the files to exclude when publishing.
Exclude []string `toml:"exclude,omitempty"`
}

// 'ModFile' is kcl package file 'kcl.mod'.
Expand Down
2 changes: 2 additions & 0 deletions pkg/package/test_data/test_data_toml/expected_reversed.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name = "MyKcl"
edition = "v0.0.1"
version = "v0.0.1"
include = ["src/", "README.md", "LICENSE"]
exclude = ["target/", ".git/", "*.log"]

[dependencies]
MyKcl1 = { git = "https://github.com/test/MyKcl1.git", tag = "v0.0.2" }
Expand Down
2 changes: 1 addition & 1 deletion pkg/package/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (pkg *Package) UnmarshalTOML(data interface{}) error {
if v, ok := meta[EXCLUDE_FLAG].([]interface{}); ok {
pkg.Exclude = convertToStringArray(v)
}

return nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/package/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func TestMarshalTOML(t *testing.T) {
Name: "MyKcl",
Edition: "v0.0.1",
Version: "v0.0.1",
Include: []string{"src/", "README.md", "LICENSE"},
Exclude: []string{"target/", ".git/", "*.log"},
},
Dependencies: Dependencies{
make(map[string]Dependency),
Expand Down Expand Up @@ -64,7 +66,7 @@ func TestMarshalTOML(t *testing.T) {
fmt.Printf("expected_toml == got_data: '%t'\n", expected_toml == got_data)
fmt.Printf("reversed_expected_toml == got_data: '%t'\n", reversed_expected_toml == got_data)
assert.Equal(t, (utils.RmNewline(expected_toml) == utils.RmNewline(got_data)) ||
(utils.RmNewline(reversed_expected_toml) == utils.RmNewline(got_data)), true)
(utils.RmNewline(reversed_expected_toml) == utils.RmNewline(got_data)), true, "got data is ", expected_toml, reversed_expected_toml, got_data)
}

func TestUnMarshalTOML(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ func (compiler *Compiler) Run() (*kcl.KCLResultList, error) {
// GetKclVersion fetches the kcl version
func GetKclVersion() string {
return string(scripts.KclvmVersionType_latest)
}
}
6 changes: 3 additions & 3 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ func TarDir(srcDir string, tarPath string, include []string, exclude []string) e

getNewPattern := func(ex string) string {
newPath := ex
if !strings.HasPrefix(ex, srcDir + "/") {
newPath = srcDir + "/" + ex
if !strings.HasPrefix(ex, srcDir+string(filepath.Separator)) {
newPath = filepath.Join(srcDir, ex)
}
return newPath
}

for _, ex := range exclude {
if matched, _ := filepath.Match(getNewPattern(ex), path); matched {
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2022 The KCL Authors. All rights reserved.
// Deprecated: The entire contents of this file will be deprecated.
// Deprecated: The entire contents of this file will be deprecated.
// Please use the kcl cli - https://github.com/kcl-lang/cli.

package version
Expand Down

0 comments on commit 015ccfb

Please sign in to comment.