Skip to content

Commit

Permalink
Merge pull request #541 from kcl-lang/add-default-settings
Browse files Browse the repository at this point in the history
fix: add default settings for API LoadKclPkgWithOpts
  • Loading branch information
Peefy authored Nov 12, 2024
2 parents 8cf5a37 + 6a19493 commit e828ddd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/package/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func LoadKclPkgWithOpts(options ...LoadOption) (*KclPkg, error) {
}

pkgPath := opts.Path
if opts.Settings == nil {
opts.Settings = settings.GetSettings()
}

modFile := new(ModFile)
err := modFile.LoadModFile(filepath.Join(pkgPath, MOD_FILE))
Expand Down
14 changes: 14 additions & 0 deletions pkg/package/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,17 @@ func TestLoadPkgFromLock(t *testing.T) {
assert.Equal(t, kpkg.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).Source.Oci.Repo, "kcl-lang/helloworld")
assert.Equal(t, kpkg.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).Source.Oci.Tag, "0.1.2")
}

func TestLoadKclPkgWithoutSettings(t *testing.T){
modPath := getTestDir("load_without_settings")
kMod, err := LoadKclPkgWithOpts(
WithPath(modPath),
)
assert.Equal(t, err, nil)
assert.Equal(t, kMod.ModFile.Dependencies.Deps.Len(), 1)
assert.Equal(t, kMod.ModFile.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).Name, "helloworld")
assert.Equal(t, kMod.ModFile.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).FullName, "helloworld_0.1.4")
assert.Equal(t, kMod.ModFile.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).Source.Oci.Reg, "ghcr.io")
assert.Equal(t, kMod.ModFile.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).Source.Oci.Repo, "kcl-lang/helloworld")
assert.Equal(t, kMod.ModFile.Dependencies.Deps.GetOrDefault("helloworld", TestPkgDependency).Source.Oci.Tag, "0.1.4")
}
7 changes: 7 additions & 0 deletions pkg/package/test_data/load_without_settings/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "load_without_settings"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = "0.1.4"
8 changes: 8 additions & 0 deletions pkg/package/test_data/load_without_settings/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[dependencies]
[dependencies.helloworld]
name = "helloworld"
full_name = "helloworld_0.1.4"
version = "0.1.4"
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
1 change: 1 addition & 0 deletions pkg/package/test_data/load_without_settings/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'

0 comments on commit e828ddd

Please sign in to comment.