diff --git a/pkg/package/package.go b/pkg/package/package.go index 6d0f8de6..87a8d949 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -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)) diff --git a/pkg/package/package_test.go b/pkg/package/package_test.go index b5a51846..3e47756b 100644 --- a/pkg/package/package_test.go +++ b/pkg/package/package_test.go @@ -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") +} \ No newline at end of file diff --git a/pkg/package/test_data/load_without_settings/kcl.mod b/pkg/package/test_data/load_without_settings/kcl.mod new file mode 100644 index 00000000..81e9a543 --- /dev/null +++ b/pkg/package/test_data/load_without_settings/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "load_without_settings" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +helloworld = "0.1.4" diff --git a/pkg/package/test_data/load_without_settings/kcl.mod.lock b/pkg/package/test_data/load_without_settings/kcl.mod.lock new file mode 100644 index 00000000..1428530e --- /dev/null +++ b/pkg/package/test_data/load_without_settings/kcl.mod.lock @@ -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" diff --git a/pkg/package/test_data/load_without_settings/main.k b/pkg/package/test_data/load_without_settings/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/package/test_data/load_without_settings/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file