From c88106f5ce4c18d4372e69bc2a955a0b961afc09 Mon Sep 17 00:00:00 2001 From: peefy Date: Thu, 28 Mar 2024 14:58:59 +0800 Subject: [PATCH] fix: oci source with settings files Signed-off-by: peefy --- pkg/client/client.go | 12 +++++++++--- pkg/client/client_test.go | 13 +++++++++++++ .../test_data/test_run_oci_with_settings/kcl.yaml | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 pkg/client/test_data/test_run_oci_with_settings/kcl.yaml diff --git a/pkg/client/client.go b/pkg/client/client.go index a8e86076..76406be0 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -378,9 +378,15 @@ func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultLis opts.Merge(kcl.WithKFilenames(filepath.Join(opts.PkgPath(), entry))) } } - } else if len(kclPkg.GetEntryKclFilesFromModFile()) == 0 && !opts.HasSettingsYaml() { - // no entry - opts.Merge(kcl.WithKFilenames(opts.PkgPath())) + } else if len(kclPkg.GetEntryKclFilesFromModFile()) == 0 { + // No entries profile in kcl.mod and no file settings in the settings file + if !opts.HasSettingsYaml() { + // No settings file. + opts.Merge(kcl.WithKFilenames(opts.PkgPath())) + } else if opts.HasSettingsYaml() && len(opts.KFilenameList) == 0 { + // Has settings file but no file config in the settings files. + opts.Merge(kcl.WithKFilenames(opts.PkgPath())) + } } opts.Merge(kcl.WithWorkDir(opts.PkgPath())) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 6173b3aa..a6d5a538 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -16,6 +16,7 @@ import ( "github.com/dominikbraun/graph" "github.com/otiai10/copy" "github.com/stretchr/testify/assert" + "kcl-lang.io/kcl-go/pkg/kcl" "kcl-lang.io/kpm/pkg/env" "kcl-lang.io/kpm/pkg/git" "kcl-lang.io/kpm/pkg/opt" @@ -1365,3 +1366,15 @@ func TestAddWithLocalPath(t *testing.T) { assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].FullName, expectpkg.Dependencies.Deps["dep_pkg"].FullName) assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].Version, expectpkg.Dependencies.Deps["dep_pkg"].Version) } + +func TestRunOciWithSettingsFile(t *testing.T) { + kpmcli, err := NewKpmClient() + assert.Equal(t, err, nil) + kpmcli.SetLogWriter(nil) + opts := opt.DefaultCompileOptions() + opts.SetEntries([]string{}) + opts.Merge(kcl.WithSettings(filepath.Join(".", "test_data", "test_run_oci_with_settings", "kcl.yaml"))) + opts.SetHasSettingsYaml(true) + _, err = kpmcli.CompileOciPkg("oci://ghcr.io/kcl-lang/helloworld", "", opts) + assert.Equal(t, err, nil) +} diff --git a/pkg/client/test_data/test_run_oci_with_settings/kcl.yaml b/pkg/client/test_data/test_run_oci_with_settings/kcl.yaml new file mode 100644 index 00000000..425cea94 --- /dev/null +++ b/pkg/client/test_data/test_run_oci_with_settings/kcl.yaml @@ -0,0 +1 @@ +kcl_cli_configs: \ No newline at end of file