Skip to content

Commit 6ed2d2e

Browse files
committed
fix: fail unit test cases
Signed-off-by: peefy <xpf6677@163.com>
1 parent f60d5bd commit 6ed2d2e

File tree

19 files changed

+49
-35
lines changed

19 files changed

+49
-35
lines changed

pkg/client/client_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ func TestDownloadLatestOci(t *testing.T) {
120120
dep, err := kpmcli.Download(&depFromOci, "", testPath)
121121
assert.Equal(t, err, nil)
122122
assert.Equal(t, dep.Name, "helloworld")
123-
assert.Equal(t, dep.FullName, "helloworld_0.1.1")
124-
assert.Equal(t, dep.Version, "0.1.1")
123+
assert.Equal(t, dep.FullName, "helloworld_0.1.2")
124+
assert.Equal(t, dep.Version, "0.1.2")
125125
assert.Equal(t, dep.Sum, "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=")
126126
assert.NotEqual(t, dep.Source.Oci, nil)
127127
assert.Equal(t, dep.Source.Oci.Reg, "ghcr.io")
128128
assert.Equal(t, dep.Source.Oci.Repo, "kcl-lang/helloworld")
129-
assert.Equal(t, dep.Source.Oci.Tag, "0.1.1")
129+
assert.Equal(t, dep.Source.Oci.Tag, "0.1.2")
130130
assert.Equal(t, dep.LocalFullPath, testPath)
131131
assert.Equal(t, err, nil)
132132

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

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

218218
// Write modFileContent to modFilePath
219-
modFileContent := `
220-
[dependencies]
221-
teleport = "0.1.0"
222-
rabbitmq = "0.0.1"
223-
gitdep = { git = "git://example.com/repo.git", tag = "v1.0.0" }
224-
localdep = { path = "/path/to/local/dependency" }
225-
`
219+
modFileContent := `[dependencies]
220+
teleport = "0.1.0"
221+
rabbitmq = "0.0.1"
222+
gitdep = { git = "git://example.com/repo.git", tag = "v1.0.0" }
223+
localdep = { path = "/path/to/local/dependency" }
224+
`
226225

227226
err = os.WriteFile(modFilePath, []byte(modFileContent), 0644)
228227
assert.Nil(t, err, "error writing mod file")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[dependencies]
2+
[dependencies.kcl1]
3+
name = "kcl1"
4+
full_name = "kcl1"
5+
sum = "c5bjxiHbwJqWCdBwXLOr9MydCTis3nJotrOzozkPsKo="
6+
[dependencies.kcl2]
7+
name = "kcl2"
8+
full_name = "kcl2"
9+
sum = "OiA7IJfhi9bLp3d+Phc6ncgWE8XwpXqkGvhF5BOpf34="

pkg/client/test_data/test_data_add_deps/kcl.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ edition = "v0.8.0"
44
version = "0.0.1"
55

66
[dependencies]
7-
oci_name = "test_tag"
7+
oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" }
88
name = { git = "test_url", tag = "test_tag" }

pkg/cmd/cmd_flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
22
// This file provides all the flags in the kpm cli.
33
//
4-
// Deprecated: The entire contents of this file will be deprecated.
4+
// Deprecated: The entire contents of this file will be deprecated.
55
// Please use the kcl cli - https://github.com/kcl-lang/cli.
66

77
package cmd

pkg/cmd/cmd_graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func KpmGraph(c *cli.Context, kpmcli *client.KpmClient) error {
7373
}
7474

7575
// print the dependency graph to stdout.
76-
root := fmt.Sprintf("%s@%s", kclPkg.GetPkgName(), kclPkg.GetPkgVersion())
76+
root := fmt.Sprintf("%s@%s", kclPkg.GetPkgName(), kclPkg.GetPkgVersion())
7777
err = graph.BFS(depGraph, root, func(source string) bool {
7878
for target := range adjMap[source] {
7979
reporter.ReportMsgTo(

pkg/cmd/cmd_import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_pkg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/cmd/cmd_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2023 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package cmd

pkg/package/modfile.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ const (
2828

2929
// 'Package' is the kcl package section of 'kcl.mod'.
3030
type Package struct {
31-
Name string `toml:"name,omitempty"` // kcl package name
32-
Edition string `toml:"edition,omitempty"` // kcl compiler version
33-
Version string `toml:"version,omitempty"` // kcl package version
34-
Description string `toml:"description,omitempty"` // kcl package description
35-
Include []string `toml:"include,omitempty"` // kcl package include
36-
Exclude []string `toml:"exclude,omitempty"` // kcl package exclude
31+
// The name of the package.
32+
Name string `toml:"name,omitempty"`
33+
// The kcl compiler version
34+
Edition string `toml:"edition,omitempty"`
35+
// The version of the package.
36+
Version string `toml:"version,omitempty"`
37+
// Description denotes the description of the package.
38+
Description string `toml:"description,omitempty"` // kcl package description
39+
// Exclude denote the files to include when publishing.
40+
Include []string `toml:"include,omitempty"`
41+
// Exclude denote the files to exclude when publishing.
42+
Exclude []string `toml:"exclude,omitempty"`
3743
}
3844

3945
// 'ModFile' is kcl package file 'kcl.mod'.

pkg/package/toml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (pkg *Package) UnmarshalTOML(data interface{}) error {
271271
if v, ok := meta[EXCLUDE_FLAG].([]interface{}); ok {
272272
pkg.Exclude = convertToStringArray(v)
273273
}
274-
274+
275275
return nil
276276
}
277277

pkg/package/toml_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestMarshalTOML(t *testing.T) {
6464
fmt.Printf("expected_toml == got_data: '%t'\n", expected_toml == got_data)
6565
fmt.Printf("reversed_expected_toml == got_data: '%t'\n", reversed_expected_toml == got_data)
6666
assert.Equal(t, (utils.RmNewline(expected_toml) == utils.RmNewline(got_data)) ||
67-
(utils.RmNewline(reversed_expected_toml) == utils.RmNewline(got_data)), true)
67+
(utils.RmNewline(reversed_expected_toml) == utils.RmNewline(got_data)), true, "got data is ", expected_toml, reversed_expected_toml, got_data)
6868
}
6969

7070
func TestUnMarshalTOML(t *testing.T) {

pkg/runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ func (compiler *Compiler) Run() (*kcl.KCLResultList, error) {
5555
// GetKclVersion fetches the kcl version
5656
func GetKclVersion() string {
5757
return string(scripts.KclvmVersionType_latest)
58-
}
58+
}

pkg/utils/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ func TarDir(srcDir string, tarPath string, include []string, exclude []string) e
149149

150150
getNewPattern := func(ex string) string {
151151
newPath := ex
152-
if !strings.HasPrefix(ex, srcDir + "/") {
153-
newPath = srcDir + "/" + ex
152+
if !strings.HasPrefix(ex, srcDir+string(filepath.Separator)) {
153+
newPath = filepath.Join(srcDir, ex)
154154
}
155155
return newPath
156156
}
157-
157+
158158
for _, ex := range exclude {
159159
if matched, _ := filepath.Match(getNewPattern(ex), path); matched {
160160
return nil

pkg/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2022 The KCL Authors. All rights reserved.
2-
// Deprecated: The entire contents of this file will be deprecated.
2+
// Deprecated: The entire contents of this file will be deprecated.
33
// Please use the kcl cli - https://github.com/kcl-lang/cli.
44

55
package version

0 commit comments

Comments
 (0)