-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: zongz <zongzhe1024@163.com>
- Loading branch information
Showing
15 changed files
with
247 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package client | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"kcl-lang.io/kpm/pkg/downloader" | ||
"kcl-lang.io/kpm/pkg/features" | ||
pkg "kcl-lang.io/kpm/pkg/package" | ||
"kcl-lang.io/kpm/pkg/utils" | ||
) | ||
|
||
func TestKclIssue1760(t *testing.T) { | ||
testPath := "github.com/kcl-lang/kcl/issues/1760" | ||
testCases := []struct { | ||
name string | ||
setup func() | ||
}{ | ||
{ | ||
name: "Default", | ||
setup: func() { | ||
features.Disable(features.SupportNewStorage) | ||
features.Disable(features.SupportMVS) | ||
}, | ||
}, | ||
{ | ||
name: "SupportNewStorage", | ||
setup: func() { | ||
features.Enable(features.SupportNewStorage) | ||
features.Disable(features.SupportMVS) | ||
}, | ||
}, | ||
{ | ||
name: "SupportMVS", | ||
setup: func() { | ||
features.Disable(features.SupportNewStorage) | ||
features.Enable(features.SupportMVS) | ||
}, | ||
}, | ||
{ | ||
name: "SupportNewStorageAndMVS", | ||
setup: func() { | ||
features.Enable(features.SupportNewStorage) | ||
features.Enable(features.SupportMVS) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc // capture range variable | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.setup() | ||
|
||
testFunc := func(t *testing.T, kpmcli *KpmClient) { | ||
rootPath := getTestDir("issues") | ||
mainKFilePath := filepath.Join(rootPath, testPath, "a", "main.k") | ||
var buf bytes.Buffer | ||
kpmcli.SetLogWriter(&buf) | ||
|
||
res, err := kpmcli.Run( | ||
WithRunSource( | ||
&downloader.Source{ | ||
Local: &downloader.Local{ | ||
Path: mainKFilePath, | ||
}, | ||
}, | ||
), | ||
) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.Contains(t, | ||
utils.RmNewline(buf.String()), | ||
"downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2'", | ||
) | ||
assert.Contains(t, | ||
utils.RmNewline(buf.String()), | ||
"downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2'", | ||
) | ||
|
||
assert.Contains(t, | ||
utils.RmNewline(buf.String()), | ||
"downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3'", | ||
) | ||
assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!") | ||
} | ||
|
||
RunTestWithGlobalLockAndKpmCli(t, testPath, testFunc) | ||
}) | ||
} | ||
} | ||
|
||
func TestKpmIssue550(t *testing.T) { | ||
testPath := "github.com/kcl-lang/kpm/issues/550" | ||
testCases := []struct { | ||
name string | ||
setup func() | ||
expected string | ||
}{ | ||
{ | ||
name: "Default", | ||
setup: func() { | ||
features.Disable(features.SupportNewStorage) | ||
features.Disable(features.SupportMVS) | ||
}, | ||
expected: filepath.Join("flask-demo-kcl-manifests_test-branch-without-modfile", "aa", "cc"), | ||
}, | ||
{ | ||
name: "SupportNewStorage", | ||
setup: func() { | ||
features.Enable(features.SupportNewStorage) | ||
features.Disable(features.SupportMVS) | ||
}, | ||
expected: filepath.Join("git", "src", "200297ed26e4aeb7", "flask-demo-kcl-manifests", "test-branch-without-modfile", "aa", "cc"), | ||
}, | ||
{ | ||
name: "SupportMVS", | ||
setup: func() { | ||
features.Disable(features.SupportNewStorage) | ||
features.Enable(features.SupportMVS) | ||
}, | ||
expected: filepath.Join("flask-demo-kcl-manifests_test-branch-without-modfile", "aa", "cc"), | ||
}, | ||
{ | ||
name: "SupportNewStorageAndMVS", | ||
setup: func() { | ||
features.Enable(features.SupportNewStorage) | ||
features.Enable(features.SupportMVS) | ||
}, | ||
expected: filepath.Join("git", "src", "200297ed26e4aeb7", "flask-demo-kcl-manifests", "test-branch-without-modfile", "aa", "cc"), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc // capture range variable | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.setup() | ||
|
||
testFunc := func(t *testing.T, kpmcli *KpmClient) { | ||
rootPath := getTestDir("issues") | ||
modPath := filepath.Join(rootPath, testPath, "pkg") | ||
var buf bytes.Buffer | ||
kpmcli.SetLogWriter(&buf) | ||
|
||
tmpKpmHome, err := os.MkdirTemp("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpKpmHome) | ||
|
||
kpmcli.homePath = tmpKpmHome | ||
|
||
kMod, err := pkg.LoadKclPkgWithOpts( | ||
pkg.WithPath(modPath), | ||
) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
res, err := kpmcli.ResolveDepsIntoMap(kMod) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
fmt.Printf("buf.String(): %v\n", buf.String()) | ||
assert.Contains(t, | ||
utils.RmNewline(buf.String()), | ||
"cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with branch 'test-branch-without-modfile'", | ||
) | ||
assert.Equal(t, len(res), 1) | ||
assert.Equal(t, res["cc"], filepath.Join(tmpKpmHome, tc.expected)) | ||
} | ||
|
||
RunTestWithGlobalLockAndKpmCli(t, testPath, testFunc) | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
pkg/client/test_data/issues/github.com/kcl-lang/kpm/issues/550/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# bug: path information is lost in kcl mod metadata | ||
|
||
|
||
## 1. Minimal reproduce step (Required) | ||
|
||
```shell | ||
kcl mod init demo | ||
cd demo | ||
kcl mod add k8s --git https://github.com/kcl-lang/modules | ||
kcl mod add k8s --rename k8soci | ||
kcl mod add json_merge_patch --git https://github.com/kcl-lang/modules --tag v0.1.0 | ||
kcl mod metadata | ||
``` | ||
|
||
## 2. What did you expect to see? (Required) | ||
|
||
Show the metadata message with local storage path. | ||
|
||
```shell | ||
{"packages":{"json_merge_patch":{"name":"json_merge_patch","manifest_path":"<real_path>"},"k8s":{"name":"k8s","manifest_path":"<real_path>"},"k8soci":{"name":"k8soci","manifest_path":"<real_path>"}}} | ||
``` | ||
|
||
## 3. What did you see instead (Required) | ||
|
||
The real path is empty. | ||
|
||
```shell | ||
{"packages":{"json_merge_patch":{"name":"json_merge_patch","manifest_path":""},"k8s":{"name":"k8s","manifest_path":""},"k8soci":{"name":"k8soci","manifest_path":""}}} | ||
``` | ||
|
||
## 4. What is your KCL components version? (Required) | ||
|
||
v0.11.0-alpha.1 |
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/issues/github.com/kcl-lang/kpm/issues/550/pkg/kcl.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "pkg" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", branch = "test-branch-without-modfile", version = "0.0.1" } |
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/issues/github.com/kcl-lang/kpm/issues/550/pkg/kcl.mod.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[dependencies] | ||
[dependencies.cc] | ||
name = "cc" | ||
full_name = "cc_0.0.1" | ||
version = "0.0.1" | ||
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" | ||
branch = "test-branch-without-modfile" |
1 change: 1 addition & 0 deletions
1
pkg/client/test_data/issues/github.com/kcl-lang/kpm/issues/550/pkg/main.k
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters