Skip to content

Commit

Permalink
exporting CliParams and RunCheck in Check subcommand for Compliance t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
modernplumbing committed Jan 11, 2023
1 parent 3738376 commit a7d9edd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions cmd/security-agent/subcommands/check/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
"github.com/DataDog/datadog-agent/pkg/util/startstop"
)

type cliParams struct {
// CliParams needs to be exported because the compliance subcommand is tightly coupled to this subcommand and tests need to be able to access this type.
type CliParams struct {
*command.GlobalParams

args []string
Expand All @@ -48,7 +49,7 @@ type cliParams struct {

// Commands returns a cobra command to run security agent checks
func Commands(globalParams *command.GlobalParams) []*cobra.Command {
checkArgs := &cliParams{}
checkArgs := &CliParams{}

cmd := &cobra.Command{
Use: "check",
Expand All @@ -63,7 +64,8 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
if checkArgs.verbose {
bundleParams.LogParams = log.LogForOneShot(bundleParams.LogParams.LoggerName(), "trace", true)
}
return fxutil.OneShot(runCheck,

return fxutil.OneShot(RunCheck,
fx.Supply(checkArgs),
fx.Supply(bundleParams),
core.Bundle,
Expand All @@ -83,7 +85,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
return []*cobra.Command{cmd}
}

func runCheck(log log.Component, config config.Component, checkArgs *cliParams) error {
func RunCheck(log log.Component, config config.Component, checkArgs *CliParams) error {
if checkArgs.skipRegoEval && checkArgs.dumpReports != "" {
return errors.New("skipping the rego evaluation does not allow the generation of reports")
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/security-agent/subcommands/check/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ func TestCommands(t *testing.T) {
tests := []struct {
name string
cliInput []string
check func(cliParams *cliParams, params core.BundleParams)
check func(cliParams *CliParams, params core.BundleParams)
}{
{
name: "check",
cliInput: []string{"check"},
check: func(cliParams *cliParams, params core.BundleParams) {
check: func(cliParams *CliParams, params core.BundleParams) {
require.Equal(t, command.LoggerName, params.LoggerName(), "logger name not matching")
require.Equal(t, "info", params.LogLevelFn(nil), "params.LogLevelFn not matching")
},
},
{
name: "verbose",
cliInput: []string{"check", "--verbose"},
check: func(cliParams *cliParams, params core.BundleParams) {
check: func(cliParams *CliParams, params core.BundleParams) {
require.Equal(t, command.LoggerName, params.LoggerName(), "logger name not matching")
require.Equal(t, "trace", params.LogLevelFn(nil), "params.LogLevelFn not matching")
},
Expand All @@ -46,7 +46,7 @@ func TestCommands(t *testing.T) {
fxutil.TestOneShotSubcommand(t,
Commands(&command.GlobalParams{}),
test.cliInput,
runCheck,
RunCheck,
test.check,
)
}
Expand Down

0 comments on commit a7d9edd

Please sign in to comment.