From b546b49abeb38f16757ac4dea2763f2bcbadb6e7 Mon Sep 17 00:00:00 2001 From: Leonardo Di Giovanna Date: Wed, 26 Feb 2025 17:25:14 +0100 Subject: [PATCH] feat(decl): rename `declarative` commands namespace to `suite` Signed-off-by: Leonardo Di Giovanna --- cmd/root.go | 16 +++++++------- cmd/{declarative => suite}/config/config.go | 12 +++++----- cmd/{declarative => suite}/config/doc.go | 4 ++-- cmd/{declarative => suite}/doc.go | 4 ++-- cmd/{declarative => suite}/explain/doc.go | 0 .../explain/encoders.go | 0 cmd/{declarative => suite}/explain/explain.go | 4 ++-- cmd/{declarative => suite}/run/doc.go | 0 cmd/{declarative => suite}/run/run.go | 4 ++-- .../declarative.go => suite/suite.go} | 22 +++++++++---------- cmd/{declarative => suite}/test/doc.go | 0 cmd/{declarative => suite}/test/test.go | 4 ++-- 12 files changed, 35 insertions(+), 35 deletions(-) rename cmd/{declarative => suite}/config/config.go (96%) rename cmd/{declarative => suite}/config/doc.go (85%) rename cmd/{declarative => suite}/doc.go (86%) rename cmd/{declarative => suite}/explain/doc.go (100%) rename cmd/{declarative => suite}/explain/encoders.go (100%) rename cmd/{declarative => suite}/explain/explain.go (98%) rename cmd/{declarative => suite}/run/doc.go (100%) rename cmd/{declarative => suite}/run/run.go (94%) rename cmd/{declarative/declarative.go => suite/suite.go} (59%) rename cmd/{declarative => suite}/test/doc.go (100%) rename cmd/{declarative => suite}/test/test.go (99%) diff --git a/cmd/root.go b/cmd/root.go index 23d97a34..a49b5c71 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,7 +31,7 @@ import ( // Initialize all k8s client auth plugins. _ "k8s.io/client-go/plugin/pkg/client/auth" - "github.com/falcosecurity/event-generator/cmd/declarative" + "github.com/falcosecurity/event-generator/cmd/suite" // register event collections. _ "github.com/falcosecurity/event-generator/events/k8saudit" _ "github.com/falcosecurity/event-generator/events/syscall" @@ -49,9 +49,9 @@ func init() { const ( // envKeysPrefix is used as environment variable prefix configuration for viper. envKeysPrefix = "falco_event_generator" - // declarativeEnvKey is used to distinguish between command-line invocation of the "declarative run" subcommand and - // the subcommand invoking itself during process chain creation. - declarativeEnvKey = "DECLARATIVE" + // suiteEnvKey is used to distinguish between command-line invocation of the "suite run" subcommand and the + // subcommand invoking itself during process chain creation. + suiteEnvKey = "SUITE" ) // New instantiates the root command. @@ -108,7 +108,7 @@ func New(configOptions *ConfigOptions) *cobra.Command { rootCmd.AddCommand(NewBench()) rootCmd.AddCommand(NewTest()) rootCmd.AddCommand(NewList()) - rootCmd.AddCommand(declarative.New(declarativeEnvKey, envKeysPrefix)) + rootCmd.AddCommand(suite.New(suiteEnvKey, envKeysPrefix)) return rootCmd } @@ -117,9 +117,9 @@ func New(configOptions *ConfigOptions) *cobra.Command { func Execute() { ctx := WithSignals(context.Background()) rootCmd := New(nil) - // declarativeEnvKey is not mapped on viper and cobra on purpose. - if v := os.Getenv(declarativeEnvKey); v != "" { - rootCmd.SetArgs([]string{"declarative", "run"}) + // suiteEnvKey is not mapped on viper and cobra on purpose. + if v := os.Getenv(suiteEnvKey); v != "" { + rootCmd.SetArgs([]string{"suite", "run"}) } if err := rootCmd.ExecuteContext(ctx); err != nil { diff --git a/cmd/declarative/config/config.go b/cmd/suite/config/config.go similarity index 96% rename from cmd/declarative/config/config.go rename to cmd/suite/config/config.go index ef9fa6ad..655582ab 100644 --- a/cmd/declarative/config/config.go +++ b/cmd/suite/config/config.go @@ -43,11 +43,11 @@ const ( TimeoutFlagName = "timeout" ) -// Config represents the configuration shared among declarative commands. Among other shared settings, it also stores -// the values of the shared flags. +// Config represents the configuration shared among `suite` commands. Among other shared settings, it also stores the +// values of the shared flags. type Config struct { - EnvKeysPrefix string - DeclarativeEnvKey string + EnvKeysPrefix string + SuiteEnvKey string // DescriptionFileEnvKey is the environment variable key corresponding to DescriptionFileFlagName. DescriptionFileEnvKey string // DescriptionDirEnvKey is the environment variable key corresponding to DescriptionDirFlagName. @@ -103,9 +103,9 @@ var containerImagePullPolicies = map[builder.ImagePullPolicy][]string{ } // New creates a new config. -func New(declarativeEnvKey, envKeysPrefix string) *Config { +func New(suiteEnvKey, envKeysPrefix string) *Config { commonConf := &Config{ - DeclarativeEnvKey: declarativeEnvKey, + SuiteEnvKey: suiteEnvKey, EnvKeysPrefix: envKeysPrefix, DescriptionFileEnvKey: envKeyFromFlagName(envKeysPrefix, DescriptionFileFlagName), DescriptionDirEnvKey: envKeyFromFlagName(envKeysPrefix, DescriptionDirFlagName), diff --git a/cmd/declarative/config/doc.go b/cmd/suite/config/doc.go similarity index 85% rename from cmd/declarative/config/doc.go rename to cmd/suite/config/doc.go index 78ec5f40..59866554 100644 --- a/cmd/declarative/config/doc.go +++ b/cmd/suite/config/doc.go @@ -13,6 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package config provides the implementation of Config, the configuration shared among declarative commands. Among -// other shared settings, it also stores the values of the shared flags. +// Package config provides the implementation of Config, the configuration shared among suite commands. Among other +// shared settings, it also stores the values of the shared flags. package config diff --git a/cmd/declarative/doc.go b/cmd/suite/doc.go similarity index 86% rename from cmd/declarative/doc.go rename to cmd/suite/doc.go index e8a5c84e..be9b013d 100644 --- a/cmd/declarative/doc.go +++ b/cmd/suite/doc.go @@ -13,5 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package declarative provides the implementation of the "declarative" command. -package declarative +// Package suite provides the implementation of the "suite" command. +package suite diff --git a/cmd/declarative/explain/doc.go b/cmd/suite/explain/doc.go similarity index 100% rename from cmd/declarative/explain/doc.go rename to cmd/suite/explain/doc.go diff --git a/cmd/declarative/explain/encoders.go b/cmd/suite/explain/encoders.go similarity index 100% rename from cmd/declarative/explain/encoders.go rename to cmd/suite/explain/encoders.go diff --git a/cmd/declarative/explain/explain.go b/cmd/suite/explain/explain.go similarity index 98% rename from cmd/declarative/explain/explain.go rename to cmd/suite/explain/explain.go index d51686de..2bf3ea98 100644 --- a/cmd/declarative/explain/explain.go +++ b/cmd/suite/explain/explain.go @@ -41,9 +41,9 @@ documentation for properties enabled only by the presence of that value. Enum requirements are evaluated in their appearing order, so order matters. The following examples demonstrate how to specify property path expressions: -event-generator declarative explain tests.context.processes +event-generator suite explain tests.context.processes -event-generator declarative explain tests.steps{type=syscall}{syscall=openat2}.args.how +event-generator suite explain tests.steps{type=syscall}{syscall=openat2}.args.how Enum requirements can be provided also by using the --with flag (see --with flag documentation for the syntax). It is not possible to specify enum requirements both with and the --with flag.` diff --git a/cmd/declarative/run/doc.go b/cmd/suite/run/doc.go similarity index 100% rename from cmd/declarative/run/doc.go rename to cmd/suite/run/doc.go diff --git a/cmd/declarative/run/run.go b/cmd/suite/run/run.go similarity index 94% rename from cmd/declarative/run/run.go rename to cmd/suite/run/run.go index d19d6e62..161fc586 100644 --- a/cmd/declarative/run/run.go +++ b/cmd/suite/run/run.go @@ -20,8 +20,8 @@ import ( "github.com/spf13/cobra" - "github.com/falcosecurity/event-generator/cmd/declarative/config" - "github.com/falcosecurity/event-generator/cmd/declarative/test" + "github.com/falcosecurity/event-generator/cmd/suite/config" + "github.com/falcosecurity/event-generator/cmd/suite/test" ) const ( diff --git a/cmd/declarative/declarative.go b/cmd/suite/suite.go similarity index 59% rename from cmd/declarative/declarative.go rename to cmd/suite/suite.go index 178580bb..141c1e96 100644 --- a/cmd/declarative/declarative.go +++ b/cmd/suite/suite.go @@ -13,27 +13,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -package declarative +package suite import ( "github.com/spf13/cobra" - "github.com/falcosecurity/event-generator/cmd/declarative/config" - "github.com/falcosecurity/event-generator/cmd/declarative/explain" - "github.com/falcosecurity/event-generator/cmd/declarative/run" - "github.com/falcosecurity/event-generator/cmd/declarative/test" + "github.com/falcosecurity/event-generator/cmd/suite/config" + "github.com/falcosecurity/event-generator/cmd/suite/explain" + "github.com/falcosecurity/event-generator/cmd/suite/run" + "github.com/falcosecurity/event-generator/cmd/suite/test" ) -// New creates a new declarative command. -func New(declarativeEnvKey, envKeysPrefix string) *cobra.Command { +// New creates a new suite command. +func New(suiteEnvKey, envKeysPrefix string) *cobra.Command { c := &cobra.Command{ - Use: "declarative", - Short: "Run test(s) specified via a YAML description", - Long: "Run test(s) specified via a YAML description", + Use: "suite", + Short: "Manage everything related to test suites", + Long: "Manage everything related to test suites", DisableAutoGenTag: true, } - commonConf := config.New(declarativeEnvKey, envKeysPrefix) + commonConf := config.New(suiteEnvKey, envKeysPrefix) runCmd := run.New(commonConf) testCmd := test.New(commonConf, false).Command diff --git a/cmd/declarative/test/doc.go b/cmd/suite/test/doc.go similarity index 100% rename from cmd/declarative/test/doc.go rename to cmd/suite/test/doc.go diff --git a/cmd/declarative/test/test.go b/cmd/suite/test/test.go similarity index 99% rename from cmd/declarative/test/test.go rename to cmd/suite/test/test.go index 17e97eb9..70ae02cf 100644 --- a/cmd/declarative/test/test.go +++ b/cmd/suite/test/test.go @@ -31,7 +31,7 @@ import ( "github.com/spf13/pflag" "github.com/thediveo/enumflag" - "github.com/falcosecurity/event-generator/cmd/declarative/config" + "github.com/falcosecurity/event-generator/cmd/suite/config" "github.com/falcosecurity/event-generator/pkg/alert/retriever/grpcretriever" "github.com/falcosecurity/event-generator/pkg/baggage" containerbuilder "github.com/falcosecurity/event-generator/pkg/container/builder" @@ -585,7 +585,7 @@ func sendTestReport(ctx context.Context, reportCh chan<- *tester.Report, report func (cw *CommandWrapper) buildRunnerEnviron(cmd *cobra.Command) []string { environ := os.Environ() environ = cw.appendFlags(environ, cmd.PersistentFlags(), cmd.Flags()) - environ = append(environ, fmt.Sprintf("%s=1", cw.DeclarativeEnvKey)) + environ = append(environ, fmt.Sprintf("%s=1", cw.SuiteEnvKey)) return environ }