Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
  • Loading branch information
AkashKumar7902 committed Feb 19, 2024
1 parent 4cc8128 commit 8c49378
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"kcl-lang.io/kpm/pkg/git"
"kcl-lang.io/kpm/pkg/opt"
pkg "kcl-lang.io/kpm/pkg/package"
"kcl-lang.io/kpm/pkg/reporter"
"kcl-lang.io/kpm/pkg/runner"
"kcl-lang.io/kpm/pkg/utils"
)
Expand Down Expand Up @@ -158,7 +159,31 @@ func TestDependencyGraph(t *testing.T) {
}

func TestCyclicDependency(t *testing.T) {

testDir := getTestDir("test_cyclic_dependency")
assert.Equal(t, utils.DirExists(filepath.Join(testDir, "aaa")), true)
assert.Equal(t, utils.DirExists(filepath.Join(testDir, "aaa/kcl.mod")), true)
assert.Equal(t, utils.DirExists(filepath.Join(testDir, "bbb")), true)
assert.Equal(t, utils.DirExists(filepath.Join(testDir, "bbb/kcl.mod")), true)

pkg_path := filepath.Join(testDir, "aaa")

kpmcli, err := NewKpmClient()
assert.Equal(t, err, nil)
kclPkg, err := kpmcli.LoadPkgFromPath(pkg_path)
assert.Equal(t, err, nil)

currentDir, err := os.Getwd()
assert.Equal(t, err, nil)
err = os.Chdir(pkg_path)
assert.Equal(t, err, nil)

_, _, err = kpmcli.InitGraphAndDownloadDeps(kclPkg)
assert.Equal(t, err, reporter.NewErrorEvent(
reporter.CircularDependencyExist, nil, "adding dependencies results in a cycle",
))

err = os.Chdir(currentDir)
assert.Equal(t, err, nil)
}

func TestInitEmptyPkg(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "aaa"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
bbb = { path = "../bbb" }
6 changes: 6 additions & 0 deletions pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dependencies]
[dependencies.bbb]
name = "bbb"
full_name = "bbb_"
sum = "Cgx5yepaNrS3/p4fK04RQWf1dEpG3j49ntFqzrJJsxU="
path = "../bbb"
7 changes: 7 additions & 0 deletions pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bbb"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
aaa = { path = "../aaa" }
8 changes: 8 additions & 0 deletions pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[dependencies]
[dependencies.aaa]
name = "aaa"
full_name = "aaa_0.0.1"
version = "0.0.1"
sum = "hgAM5wYFzXo83S+OiT0LaBDnHU7Q9vqq3BPXlTDr8TY="
path = "../aaa"

0 comments on commit 8c49378

Please sign in to comment.