-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix redownload when the remote repo has no mod file (#542)
* fix: fix redownload when the remote repo has no mod file Signed-off-by: zongz <[email protected]> * fix: move test case into global lock Signed-off-by: zongz <[email protected]> * fix: fix test case Signed-off-by: zongz <[email protected]> * fix: fix test case TestGraph Signed-off-by: zongz <[email protected]> * fix: fix test case Signed-off-by: zongz <[email protected]> * refactor: refactor test utils to create a separate kpm home for testing Signed-off-by: zongz <[email protected]> * fix: move some test into separate kpm home Signed-off-by: zongz <[email protected]> --------- Signed-off-by: zongz <[email protected]>
- Loading branch information
Showing
18 changed files
with
302 additions
and
159 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,8 +4,8 @@ import ( | |
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"golang.org/x/mod/module" | ||
"gotest.tools/v3/assert" | ||
pkg "kcl-lang.io/kpm/pkg/package" | ||
"kcl-lang.io/kpm/pkg/utils" | ||
) | ||
|
@@ -43,5 +43,7 @@ func testGraph(t *testing.T) { | |
t.Fatalf("failed to display graph: %v", err) | ||
} | ||
|
||
assert.Equal(t, utils.RmNewline(graStr), "[email protected] [email protected]@0.0.1 [email protected]@0.0.1 [email protected]") | ||
assert.Contains(t, utils.RmNewline(graStr), "[email protected] [email protected]") | ||
assert.Contains(t, utils.RmNewline(graStr), "[email protected] [email protected]") | ||
assert.Contains(t, utils.RmNewline(graStr), "[email protected] [email protected]") | ||
} |
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,60 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
const testDataDir = "test_data" | ||
|
||
func getTestDir(subDir string) string { | ||
pwd, _ := os.Getwd() | ||
testDir := filepath.Join(pwd, testDataDir) | ||
testDir = filepath.Join(testDir, subDir) | ||
|
||
return testDir | ||
} | ||
|
||
func initTestDir(subDir string) string { | ||
testDir := getTestDir(subDir) | ||
// clean the test data | ||
_ = os.RemoveAll(testDir) | ||
_ = os.Mkdir(testDir, 0755) | ||
|
||
return testDir | ||
} | ||
|
||
// Use a global variable to store the kpmcli instance. | ||
func RunTestWithGlobalLockAndKpmCli(t *testing.T, name string, testFunc func(t *testing.T, kpmcli *KpmClient)) { | ||
t.Run(name, func(t *testing.T) { | ||
kpmcli, err := NewKpmClient() | ||
if err != nil { | ||
t.Errorf("Error acquiring lock: %v", err) | ||
} | ||
err = kpmcli.AcquirePackageCacheLock() | ||
if err != nil { | ||
t.Errorf("Error acquiring lock: %v", err) | ||
} | ||
|
||
defer func() { | ||
err = kpmcli.ReleasePackageCacheLock() | ||
if err != nil { | ||
t.Errorf("Error acquiring lock: %v", err) | ||
} | ||
}() | ||
|
||
// create a tmp dir as kpm home for test | ||
tmpDir, err := os.MkdirTemp("", "") | ||
if err != nil { | ||
t.Errorf("Error acquiring lock: %v", err) | ||
} | ||
// clean the temp dir. | ||
defer os.RemoveAll(tmpDir) | ||
kpmcli.SetHomePath(tmpDir) | ||
|
||
testFunc(t, kpmcli) | ||
fmt.Printf("%s completed\n", name) | ||
}) | ||
} |
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,4 @@ | ||
[package] | ||
name = "git" | ||
edition = "v0.10.0" | ||
version = "0.0.1" |
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/add_with_mod_spec/git_mod_0/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 = "git" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "8308200", version = "0.0.1" } |
Empty file.
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/add_with_mod_spec/git_mod_0/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,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" | ||
commit = "8308200" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "git" | ||
edition = "v0.10.0" | ||
version = "0.0.1" |
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/add_with_mod_spec/git_mod_1/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 = "git" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "5ab0fff", version = "0.0.1" } |
Empty file.
7 changes: 7 additions & 0 deletions
7
pkg/client/test_data/add_with_mod_spec/git_mod_1/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,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" | ||
commit = "5ab0fff" |
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
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.newpkg] | ||
name = "newpkg" | ||
full_name = "newpkg_0.0.1" | ||
version = "0.0.1" | ||
reg = "ghcr.io" | ||
repo = "kcl-lang/helloworld" | ||
oci_tag = "0.1.4" |
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