From d44af6911726baf9fe27195bc109625e29f07711 Mon Sep 17 00:00:00 2001 From: Preslav Date: Mon, 11 Dec 2023 20:44:14 +0200 Subject: [PATCH] some renaming. --- apps/cnspec/cmd/scan.go | 4 ++-- cli/reporter/file_handler_test.go | 2 +- cli/reporter/output_handler.go | 4 ++-- cli/reporter/output_handler_test.go | 6 +++--- test/cli/cli_test.go | 6 ++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/cnspec/cmd/scan.go b/apps/cnspec/cmd/scan.go index 3fafcd54..b19ffc6f 100644 --- a/apps/cnspec/cmd/scan.go +++ b/apps/cnspec/cmd/scan.go @@ -143,12 +143,12 @@ var scanCmdRun = func(cmd *cobra.Command, runtime *providers.Runtime, cliRes *pl logger.DebugDumpJSON("report", report) - cliConf := reporter.ReportConfig{ + handlerConf := reporter.HandlerConfig{ Format: conf.OutputFormat, OutputTarget: conf.OutputTarget, Incognito: conf.IsIncognito, } - outputHandler, err := reporter.NewOutputHandler(cliConf) + outputHandler, err := reporter.NewOutputHandler(handlerConf) if err != nil { log.Fatal().Err(err).Msg("failed to create an output handler") } diff --git a/cli/reporter/file_handler_test.go b/cli/reporter/file_handler_test.go index 2eb2495c..0096e74e 100644 --- a/cli/reporter/file_handler_test.go +++ b/cli/reporter/file_handler_test.go @@ -26,7 +26,7 @@ func TestFileHandler(t *testing.T) { now := time.Now().Format(time.RFC3339) fileName := fmt.Sprintf("/tmp/%s-testfilehandler.json", now) - config := ReportConfig{Format: "compact", OutputTarget: fileName} + config := HandlerConfig{Format: "compact", OutputTarget: fileName} handler, err := NewOutputHandler(config) require.NoError(t, err) err = handler.WriteReport(context.Background(), yr) diff --git a/cli/reporter/output_handler.go b/cli/reporter/output_handler.go index 63cc22e3..6aa12f19 100644 --- a/cli/reporter/output_handler.go +++ b/cli/reporter/output_handler.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/yaml" ) -type ReportConfig struct { +type HandlerConfig struct { Format string OutputTarget string Incognito bool @@ -33,7 +33,7 @@ type OutputHandler interface { WriteReport(ctx context.Context, report *policy.ReportCollection) error } -func NewOutputHandler(config ReportConfig) (OutputHandler, error) { +func NewOutputHandler(config HandlerConfig) (OutputHandler, error) { format, ok := Formats[strings.ToLower(config.Format)] if !ok { return nil, errors.New("unknown output format '" + config.Format + "'. Available: " + AllFormats()) diff --git a/cli/reporter/output_handler_test.go b/cli/reporter/output_handler_test.go index aec61ff1..5dcb0295 100644 --- a/cli/reporter/output_handler_test.go +++ b/cli/reporter/output_handler_test.go @@ -20,7 +20,7 @@ func TestOutputHandlerAwsSqs(t *testing.T) { } for i, sqsUrl := range sqsUrls { - rep, err := NewOutputHandler(ReportConfig{Format: "JSON", OutputTarget: sqsUrl}) + rep, err := NewOutputHandler(HandlerConfig{Format: "JSON", OutputTarget: sqsUrl}) require.NoError(t, err, i) require.IsType(t, &awsSqsHandler{}, rep, i) } @@ -36,14 +36,14 @@ func TestOutputHandlerFileLocal(t *testing.T) { } for i, f := range fileTargets { - rep, err := NewOutputHandler(ReportConfig{Format: "JSON", OutputTarget: f}) + rep, err := NewOutputHandler(HandlerConfig{Format: "JSON", OutputTarget: f}) require.NoError(t, err, i) require.IsType(t, &localFileHandler{}, rep, i) } } func TestCliReporter(t *testing.T) { - rep, err := NewOutputHandler(ReportConfig{}) + rep, err := NewOutputHandler(HandlerConfig{}) require.NoError(t, err) require.IsType(t, &Reporter{}, rep) } diff --git a/test/cli/cli_test.go b/test/cli/cli_test.go index 4c9273d3..4292834a 100644 --- a/test/cli/cli_test.go +++ b/test/cli/cli_test.go @@ -14,8 +14,10 @@ import ( "go.mondoo.com/cnspec/v9/apps/cnspec/cmd" ) -var once sync.Once -var cnspecCmd *cobra.Command +var ( + once sync.Once + cnspecCmd *cobra.Command +) func setup() { var err error