-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a test case for 'k8s = {version = "1.27"}'
Signed-off-by: zongz <zongzhe1024@163.com>
- Loading branch information
Showing
6 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package client | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/otiai10/copy" | ||
"gotest.tools/v3/assert" | ||
"kcl-lang.io/kpm/pkg/downloader" | ||
"kcl-lang.io/kpm/pkg/utils" | ||
) | ||
|
||
func TestRunWithModSpecVersion(t *testing.T) { | ||
pkgPath := getTestDir("test_run_with_modspec_version") | ||
modbkPath := filepath.Join(pkgPath, "kcl.mod.bk") | ||
modPath := filepath.Join(pkgPath, "kcl.mod") | ||
modExpect := filepath.Join(pkgPath, "kcl.mod.expect") | ||
lockbkPath := filepath.Join(pkgPath, "kcl.mod.lock.bk") | ||
lockPath := filepath.Join(pkgPath, "kcl.mod.lock") | ||
lockExpect := filepath.Join(pkgPath, "kcl.mod.lock.expect") | ||
err := copy.Copy(modbkPath, modPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = copy.Copy(lockbkPath, lockPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
// remove the copied files | ||
err := os.RemoveAll(modPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = os.RemoveAll(lockPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
kpmcli, err := NewKpmClient() | ||
if err != nil { | ||
t.Errorf("Failed to create kpm client: %v", err) | ||
} | ||
|
||
res, err := kpmcli.Run( | ||
WithRunSource( | ||
&downloader.Source{ | ||
Local: &downloader.Local{ | ||
Path: pkgPath, | ||
}, | ||
}, | ||
), | ||
) | ||
|
||
if err != nil { | ||
t.Errorf("Failed to run package: %v", err) | ||
} | ||
|
||
assert.Equal(t, res.GetRawYamlResult(), "res: Hello World!") | ||
expectedMod, err := os.ReadFile(modExpect) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
gotMod, err := os.ReadFile(modPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expectedLock, err := os.ReadFile(lockExpect) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
gotLock, err := os.ReadFile(lockPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.Equal(t, utils.RmNewline(string(expectedMod)), utils.RmNewline(string(gotMod))) | ||
assert.Equal(t, utils.RmNewline(string(expectedLock)), utils.RmNewline(string(gotLock))) | ||
} |
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/test_run_with_modspec_version/kcl.mod.bk
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 = "test_run_with_modspec_version" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
helloworld = { version = "0.1.2" } |
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/test_run_with_modspec_version/kcl.mod.expect
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 = "test_run_with_modspec_version" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
helloworld = { version = "0.1.2" } |
8 changes: 8 additions & 0 deletions
8
pkg/client/test_data/test_run_with_modspec_version/kcl.mod.lock.bk
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,8 @@ | ||
[dependencies] | ||
[dependencies.helloworld] | ||
name = "helloworld" | ||
full_name = "helloworld_0.1.2" | ||
version = "0.1.2" | ||
reg = "ghcr.io" | ||
repo = "kcl-lang/helloworld" | ||
oci_tag = "0.1.2" |
8 changes: 8 additions & 0 deletions
8
pkg/client/test_data/test_run_with_modspec_version/kcl.mod.lock.expect
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,8 @@ | ||
[dependencies] | ||
[dependencies.helloworld] | ||
name = "helloworld" | ||
full_name = "helloworld_0.1.2" | ||
version = "0.1.2" | ||
reg = "ghcr.io" | ||
repo = "kcl-lang/helloworld" | ||
oci_tag = "0.1.2" |
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,3 @@ | ||
import helloworld | ||
|
||
res = helloworld.The_first_kcl_program |