From 3684f9e1b2969f16d2696b14b40d25fefa78fa11 Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 4 Dec 2023 17:44:40 +0800 Subject: [PATCH 1/2] feat: align the compile arguments in kcl.mod with the kcl.yaml Signed-off-by: zongz --- pkg/api/kpm_run.go | 2 +- pkg/client/client.go | 8 +-- pkg/cmd/cmd_flags.go | 1 + pkg/cmd/cmd_run.go | 14 +--- pkg/package/modfile.go | 65 +++++++++++++++---- pkg/package/package.go | 12 +++- pkg/package/toml.go | 4 +- .../test_suite.env | 2 + .../test_suite.input | 1 + .../test_suite.stderr | 0 .../test_suite.stdout | 1 + .../test_suite.env | 2 + .../test_suite.input | 1 + .../test_suite.stderr | 0 .../test_suite.stdout | 2 + .../test_suite.env | 2 + .../test_suite.input | 1 + .../test_suite.stderr | 0 .../test_suite.stdout | 6 ++ .../test_suite.env | 2 + .../test_suite.input | 1 + .../test_suite.stderr | 0 .../test_suite.stdout | 1 + .../test_suite.env | 2 + .../test_suite.input | 1 + .../test_suite.stderr | 0 .../test_suite.stdout | 2 + .../kcl.mod | 7 ++ .../kcl.mod.lock | 0 .../main.k | 1 + .../test_kpm_run_with_option_profile/kcl.mod | 8 +++ .../kcl.mod.lock | 0 .../test_kpm_run_with_option_profile/main.k | 2 + .../kcl.mod | 7 ++ .../kcl.mod.lock | 0 .../test_kpm_run_with_override_profile/main.k | 11 ++++ .../kcl.mod | 7 ++ .../kcl.mod.lock | 0 .../main.k | 6 ++ .../kcl.mod | 7 ++ .../kcl.mod.lock | 0 .../test_kpm_run_with_sort_key_profile/main.k | 2 + 42 files changed, 157 insertions(+), 34 deletions(-) create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.env create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.input create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stderr create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stdout create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.env create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.input create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stderr create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stdout create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.env create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.input create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stderr create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stdout create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.env create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.input create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stderr create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stdout create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.env create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.input create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stderr create mode 100644 test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stdout create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/main.k create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/main.k create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/main.k create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/main.k create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod.lock create mode 100644 test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/main.k diff --git a/pkg/api/kpm_run.go b/pkg/api/kpm_run.go index d2eb067c..8f11a8e6 100644 --- a/pkg/api/kpm_run.go +++ b/pkg/api/kpm_run.go @@ -243,7 +243,7 @@ func run(kpmcli *client.KpmClient, opts *opt.CompileOptions) (*kcl.KCLResultList } } // add entry from 'kcl.mod' - } else if len(kclPkg.GetEntryKclFilesFromModFile()) > 0 { + } else if kclPkg.HasProfile() { opts.Merge(*kclPkg.GetKclOpts()) } else if !opts.HasSettingsYaml() { // no entry diff --git a/pkg/client/client.go b/pkg/client/client.go index 870acdda..a6247a73 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -313,7 +313,8 @@ func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultLis if err != (*reporter.KpmEvent)(nil) { return nil, err } - + // add all the options from 'kcl.mod' + opts.Merge(*kclPkg.GetKclOpts()) if len(opts.Entries()) > 0 { // add entry from '--input' for _, entry := range opts.Entries() { @@ -323,10 +324,7 @@ func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultLis opts.Merge(kcl.WithKFilenames(filepath.Join(opts.PkgPath(), entry))) } } - // add entry from 'kcl.mod' - } else if len(kclPkg.GetEntryKclFilesFromModFile()) > 0 { - opts.Merge(*kclPkg.GetKclOpts()) - } else if !opts.HasSettingsYaml() { + } else if len(kclPkg.GetEntryKclFilesFromModFile()) == 0 && !opts.HasSettingsYaml() { // no entry opts.Merge(kcl.WithKFilenames(opts.PkgPath())) } diff --git a/pkg/cmd/cmd_flags.go b/pkg/cmd/cmd_flags.go index 12bbb9d7..1f34c2f6 100644 --- a/pkg/cmd/cmd_flags.go +++ b/pkg/cmd/cmd_flags.go @@ -13,4 +13,5 @@ const FLAG_DISABLE_NONE = "disable_none" const FLAG_ARGUMENT = "argument" const FLAG_OVERRIDES = "overrides" const FLAG_SORT_KEYS = "sort_keys" + const FLAG_QUIET = "quiet" diff --git a/pkg/cmd/cmd_run.go b/pkg/cmd/cmd_run.go index d703dc12..1a59f933 100644 --- a/pkg/cmd/cmd_run.go +++ b/pkg/cmd/cmd_run.go @@ -166,20 +166,10 @@ func CompileOptionFromCli(c *cli.Context) *opt.CompileOptions { } // --argument, -D - argumentsOpt := c.StringSlice(FLAG_ARGUMENT) - if len(argumentsOpt) != 0 { - for _, arg := range argumentsOpt { - opts.Merge(kcl.WithOptions(arg)) - } - } + opts.Merge(kcl.WithOptions(c.StringSlice(FLAG_ARGUMENT)...)) // --overrides, -O - overridesOpt := c.StringSlice(FLAG_OVERRIDES) - if len(overridesOpt) != 0 { - for _, override := range overridesOpt { - opts.Merge(kcl.WithOverrides(override)) - } - } + opts.Merge(kcl.WithOverrides(c.StringSlice(FLAG_OVERRIDES)...)) // --disable_none, -n opts.Merge(kcl.WithDisableNone(c.Bool(FLAG_DISABLE_NONE))) diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index 4ce754ea..6fa39847 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -34,22 +34,25 @@ type ModFile struct { // Whether the current package uses the vendor mode // In the vendor mode, kpm will look for the package in the vendor subdirectory // in the current package directory. - VendorMode bool `toml:"-"` - Profiles Profile `toml:"profile"` + VendorMode bool `toml:"-"` + Profiles *Profile `toml:"profile"` Dependencies } // Profile is the profile section of 'kcl.mod'. // It is used to specify the compilation options of the current package. type Profile struct { - Entries []string `toml:"entries"` + Entries *[]string `toml:"entries"` + DisableNone *bool `toml:"disable_none"` + SortKeys *bool `toml:"sort_keys"` + Selectors *[]string `toml:"selectors"` + Overrides *[]string `toml:"overrides"` + Options *[]string `toml:"arguments"` } // NewProfile will create a new profile. func NewProfile() Profile { - return Profile{ - Entries: []string{}, - } + return Profile{} } // IntoKclOptions will transform the profile into kcl options. @@ -57,18 +60,48 @@ func (profile *Profile) IntoKclOptions() *kcl.Option { opts := kcl.NewOption() - for _, entry := range profile.Entries { - ext := filepath.Ext(entry) - if ext == ".yaml" { - opts.Merge(kcl.WithSettings(entry)) - } else { - opts.Merge(kcl.WithKFilenames(entry)) + if profile.Entries != nil { + for _, entry := range *profile.Entries { + ext := filepath.Ext(entry) + if ext == ".yaml" { + opts.Merge(kcl.WithSettings(entry)) + } else { + opts.Merge(kcl.WithKFilenames(entry)) + } } } + if profile.DisableNone != nil { + opts.Merge(kcl.WithDisableNone(*profile.DisableNone)) + } + + if profile.SortKeys != nil { + opts.Merge(kcl.WithSortKeys(*profile.SortKeys)) + } + + if profile.Selectors != nil { + opts.Merge(kcl.WithSelectors(*profile.Selectors...)) + } + + if profile.Overrides != nil { + opts.Merge(kcl.WithOverrides(*profile.Overrides...)) + } + + if profile.Options != nil { + opts.Merge(kcl.WithOptions(*profile.Options...)) + } + return opts } +// GetEntries will get the entry kcl files from profile. +func (profile *Profile) GetEntries() []string { + if profile.Entries == nil { + return []string{} + } + return *profile.Entries +} + // FillDependenciesInfo will fill registry information for all dependencies in a kcl.mod. func (modFile *ModFile) FillDependenciesInfo() error { for k, v := range modFile.Deps { @@ -81,6 +114,14 @@ func (modFile *ModFile) FillDependenciesInfo() error { return nil } +// GetEntries will get the entry kcl files from kcl.mod. +func (modFile *ModFile) GetEntries() []string { + if modFile.Profiles == nil { + return []string{} + } + return modFile.Profiles.GetEntries() +} + // 'Dependencies' is dependencies section of 'kcl.mod'. type Dependencies struct { Deps map[string]Dependency `json:"packages" toml:"dependencies,omitempty"` diff --git a/pkg/package/package.go b/pkg/package/package.go index beff8eb4..a20f7f9c 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -60,12 +60,20 @@ func LoadKclPkgFromTar(pkgTarPath string) (*KclPkg, error) { // GetKclOpts will return the kcl options from kcl.mod. func (kclPkg *KclPkg) GetKclOpts() *kcl.Option { + if kclPkg.ModFile.Profiles == nil { + return kcl.NewOption() + } return kclPkg.ModFile.Profiles.IntoKclOptions() } // GetEntryKclFilesFromModFile will return the entry kcl files from kcl.mod. func (kclPkg *KclPkg) GetEntryKclFilesFromModFile() []string { - return kclPkg.ModFile.Profiles.Entries + return kclPkg.ModFile.GetEntries() +} + +// HasProfile will return true if the current kcl package has the profile. +func (kclPkg *KclPkg) HasProfile() bool { + return kclPkg.ModFile.Profiles != nil } func (kclPkg *KclPkg) IsVendorMode() bool { @@ -170,7 +178,7 @@ func (kclPkg *KclPkg) GetPkgEdition() string { // GetPkgProfile returns the profile of package. func (kclPkg *KclPkg) GetPkgProfile() Profile { - return kclPkg.ModFile.Profiles + return *kclPkg.ModFile.Profiles } // GetPkgTarName returns the kcl package tar name "-v.tar" diff --git a/pkg/package/toml.go b/pkg/package/toml.go index f4dc84c3..520b22c7 100644 --- a/pkg/package/toml.go +++ b/pkg/package/toml.go @@ -147,7 +147,7 @@ const PROFILE_PATTERN = "[profile]" func (p *Profile) MarshalTOML() string { var sb strings.Builder - if len(p.Entries) != 0 { + if p != nil { sb.WriteString(PROFILE_PATTERN) sb.WriteString(NEWLINE) var buf bytes.Buffer @@ -202,7 +202,7 @@ func (mod *ModFile) UnmarshalTOML(data interface{}) error { if err != nil { return err } - mod.Profiles = p + mod.Profiles = &p } return nil } diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.input new file mode 100644 index 00000000..b02e55a1 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.input @@ -0,0 +1 @@ +kpm run \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stdout new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_disable_none_profile/test_suite.stdout @@ -0,0 +1 @@ + diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.input new file mode 100644 index 00000000..b02e55a1 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.input @@ -0,0 +1 @@ +kpm run \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stdout new file mode 100644 index 00000000..811b4513 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_option_profile/test_suite.stdout @@ -0,0 +1,2 @@ +The_first_kcl_program1: Hello1 +The_first_kcl_program2: Hello2 diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.input new file mode 100644 index 00000000..b02e55a1 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.input @@ -0,0 +1 @@ +kpm run \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stdout new file mode 100644 index 00000000..b86eed91 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_override_profile/test_suite.stdout @@ -0,0 +1,6 @@ +a1: + image: default + name: a1-app +a2: + image: new-a2-image:v123 + name: app diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.input new file mode 100644 index 00000000..b02e55a1 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.input @@ -0,0 +1 @@ +kpm run \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stdout new file mode 100644 index 00000000..2ae69695 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_path_selector_profile/test_suite.stdout @@ -0,0 +1 @@ +yellow \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.input new file mode 100644 index 00000000..b02e55a1 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.input @@ -0,0 +1 @@ +kpm run \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stdout new file mode 100644 index 00000000..13785319 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_sort_key_profile/test_suite.stdout @@ -0,0 +1,2 @@ +a: 2 +b: 1 diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod new file mode 100644 index 00000000..3b643fa3 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "test_kpm_run_with_disable_none" +edition = "0.0.1" +version = "0.0.1" + +[profile] +path_selector = true diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/main.k b/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/main.k new file mode 100644 index 00000000..6f12b94c --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_disable_none_profile/main.k @@ -0,0 +1 @@ +The_first_kcl_program = None \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod new file mode 100644 index 00000000..9e1add50 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod @@ -0,0 +1,8 @@ +[package] +name = "test_kpm_run_with_option" +edition = "0.0.1" +version = "0.0.1" + +[profile] +arguments = ["name1=Hello1", "name2=Hello2"] + diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/main.k b/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/main.k new file mode 100644 index 00000000..dc6fe814 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_option_profile/main.k @@ -0,0 +1,2 @@ +The_first_kcl_program1 = option("name1") +The_first_kcl_program2 = option("name2") \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod new file mode 100644 index 00000000..f1760e27 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "test_kpm_run_with_override" +edition = "0.0.1" +version = "0.0.1" + +[profile] +overrides = [ "__main__:a2.image=\"new-a2-image:v123\"" ] \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/main.k b/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/main.k new file mode 100644 index 00000000..d5a6f7ab --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_override_profile/main.k @@ -0,0 +1,11 @@ +schema App: + image: str = "default" + name: str = "app" + +a1 = App { + name = "a1-app" +} + +a2 = App { + image = "a2" +} \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod new file mode 100644 index 00000000..cde8156e --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "test_kpm_run_with_disable_none" +edition = "0.0.1" +version = "0.0.1" + +[profile] +path_selector = "alice.labels.skin" \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/main.k b/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/main.k new file mode 100644 index 00000000..706d3005 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_path_selector_profile/main.k @@ -0,0 +1,6 @@ +schema Person: + labels: {str:str} + +alice = Person { + "labels": {"skin": "yellow"} +} \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod new file mode 100644 index 00000000..99dfe86c --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "test_kpm_run_with_sort_key" +edition = "0.0.1" +version = "0.0.1" + +[profile] +sort_keys = true \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/main.k b/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/main.k new file mode 100644 index 00000000..4eda9524 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_sort_key_profile/main.k @@ -0,0 +1,2 @@ +b = 1 +a = 2 From 00e66c534f68d16b19890281ba1681b5db488086 Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 4 Dec 2023 19:34:40 +0800 Subject: [PATCH 2/2] fix: fix failed test case Signed-off-by: zongz --- pkg/package/toml_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/package/toml_test.go b/pkg/package/toml_test.go index 64e27903..b9ef5f95 100644 --- a/pkg/package/toml_test.go +++ b/pkg/package/toml_test.go @@ -167,5 +167,5 @@ func TestUnMarshalTOMLWithProfile(t *testing.T) { assert.Equal(t, modfile.Pkg.Name, "kpm") assert.Equal(t, modfile.Pkg.Version, "0.0.1") assert.Equal(t, modfile.Pkg.Edition, "0.0.1") - assert.Equal(t, modfile.Profiles.Entries, []string{"main.k", "xxx/xxx/dir", "test.yaml"}) + assert.Equal(t, *modfile.Profiles.Entries, []string{"main.k", "xxx/xxx/dir", "test.yaml"}) }