Skip to content

Commit

Permalink
fix: fill the missing checksum in kcl.mod.lock in api Update (#546)
Browse files Browse the repository at this point in the history
* fix: fill the missing checksum in kcl.mod.lock in api Update

Signed-off-by: zongz <zongzhe1024@163.com>

* fix: fill missing sum in test cases

Signed-off-by: zongz <zongzhe1024@163.com>

* fix: fix test case

Signed-off-by: zongz <zongzhe1024@163.com>

* fix: fill missing sum in test cases

Signed-off-by: zongz <zongzhe1024@163.com>

---------

Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe authored Nov 15, 2024
1 parent ad777e1 commit 840dc89
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,9 @@ func testAddWithNoSumCheck(t *testing.T) {

func testUpdateWithNoSumCheck(t *testing.T, kpmcli *KpmClient) {
pkgPath := getTestDir("test_update_no_sum_check")
defer func() {
_ = os.Remove(filepath.Join(pkgPath, "kcl.mod.lock"))
}()

var buf bytes.Buffer
kpmcli.SetLogWriter(&buf)
Expand All @@ -1201,15 +1204,12 @@ func testUpdateWithNoSumCheck(t *testing.T, kpmcli *KpmClient) {
kpmcli.SetNoSumCheck(false)
kclPkg, err = kpmcli.LoadPkgFromPath(pkgPath)
assert.Equal(t, err, nil)
kclPkg.NoSumCheck = false

err = kpmcli.UpdateDeps(kclPkg)
assert.Equal(t, err, nil)
assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "kcl.mod.lock")), true)
assert.Equal(t, buf.String(), "")

defer func() {
_ = os.Remove(filepath.Join(pkgPath, "kcl.mod.lock"))
}()
}

func testAddWithDiffVersionNoSumCheck(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "subhelloworld"
full_name = "subhelloworld_0.0.1"
version = "0.0.1"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "helloworld"
full_name = "helloworld_0.1.4"
version = "0.1.4"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "helloworld"
full_name = "helloworld_0.1.4"
version = "0.1.4"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "subhelloworld"
full_name = "subhelloworld_0.0.1"
version = "0.0.1"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "newpkg"
full_name = "helloworld_0.1.4"
version = "0.1.4"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "newpkg"
full_name = "helloworld_0.1.2"
version = "0.1.2"
sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.2"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "helloworld"
full_name = "helloworld_0.1.4"
version = "0.1.4"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "helloworld"
full_name = "helloworld_0.1.4"
version = "0.1.4"
sum = "9J9HOMhdypaDYf0J7PqtpGTdlkbxkN0HFEYhosHhf4U="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
20 changes: 9 additions & 11 deletions pkg/client/test_data/test_data_add_deps/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[dependencies]
[dependencies.oci_test]
[dependencies.name]
name = "name"
full_name = "test_url_test_tag"
version = "test_tag"
url = "test_url"
git_tag = "test_tag"
[dependencies.oci_name]
name = "oci_name"
full_name = "test_version"
version = "test_version"
sum = "test_sum"
full_name = "oci_name_test_tag"
version = "test_tag"
reg = "test_reg"
repo = "test_repo"
oci_tag = "test_tag"
[dependencies.test]
name = "name"
full_name = "test_version"
version = "test_version"
sum = "test_sum"
url = "test_url"
git_tag = "test_tag"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name = "helloworld"
full_name = "helloworld_0.1.2"
version = "0.1.2"
sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[dependencies]
[dependencies.helloworld]
name = "helloworld"
full_name = "helloworld_0.1.2"
version = "0.1.2"
sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.2"
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
[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"
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
full_name = "helloworld_0.1.0"
version = "0.1.0"
sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
full_name = "helloworld_0.1.1"
version = "0.1.1"
sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.1"
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
name = "helloworld"
full_name = "helloworld_0.1.0"
version = "0.1.0"
sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
name = "helloworld"
full_name = "helloworld_0.1.1"
version = "0.1.1"
sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.1"
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
full_name = "helloworld_0.1.0"
version = "0.1.0"
sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
full_name = "helloworld_0.1.1"
version = "0.1.1"
sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.1"
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
name = "helloworld"
full_name = "helloworld_0.1.0"
version = "0.1.0"
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
name = "helloworld"
full_name = "helloworld_0.1.1"
version = "0.1.1"
sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ="
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.1"
11 changes: 11 additions & 0 deletions pkg/client/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (c *KpmClient) Update(options ...UpdateOption) (*pkg.KclPkg, error) {
return nil, fmt.Errorf("kcl package is nil")
}

kMod.NoSumCheck = c.noSumCheck

modDeps := kMod.ModFile.Dependencies.Deps
if modDeps == nil {
return nil, fmt.Errorf("kcl.mod dependencies is nil")
Expand Down Expand Up @@ -80,6 +82,15 @@ func (c *KpmClient) Update(options ...UpdateOption) (*pkg.KclPkg, error) {
}
}
selectedDep.LocalFullPath = dep.LocalFullPath
if selectedDep.Sum == "" {
sum, err := c.AcquireDepSum(*selectedDep)
if err != nil {
return err
}
if sum != "" {
selectedDep.Sum = sum
}
}
kMod.Dependencies.Deps.Set(dep.Name, *selectedDep)

return nil
Expand Down

0 comments on commit 840dc89

Please sign in to comment.