-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CWS Agent] Moving SecAgent subcommands to new dir part 2 (#14915)
* moving flare command to subcommands dir * consolidating and moving secagent config package * moving runtime to subcommands dir * moved check subcommand, updated compliance subcommand which is the entry point to check funcs * moving compliance cmd to subcommand dir * exporting CliParams and RunCheck in Check subcommand for Compliance tests * fixing cluster agent entry point into the check subcommand
- Loading branch information
1 parent
839b9d6
commit 9707350
Showing
18 changed files
with
368 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build !windows && kubeapiserver | ||
// +build !windows,kubeapiserver | ||
|
||
package check | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/DataDog/datadog-agent/cmd/security-agent/command" | ||
"github.com/DataDog/datadog-agent/comp/core" | ||
"github.com/DataDog/datadog-agent/pkg/util/fxutil" | ||
) | ||
|
||
func TestCommands(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cliInput []string | ||
check func(cliParams *CliParams, params core.BundleParams) | ||
}{ | ||
{ | ||
name: "check", | ||
cliInput: []string{"check"}, | ||
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) { | ||
require.Equal(t, command.LoggerName, params.LoggerName(), "logger name not matching") | ||
require.Equal(t, "trace", params.LogLevelFn(nil), "params.LogLevelFn not matching") | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
fxutil.TestOneShotSubcommand(t, | ||
Commands(&command.GlobalParams{}), | ||
test.cliInput, | ||
RunCheck, | ||
test.check, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
cmd/security-agent/subcommands/compliance/command_kubeapiserver_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build !windows && kubeapiserver | ||
// +build !windows,kubeapiserver | ||
|
||
package compliance | ||
|
||
import ( | ||
"github.com/DataDog/datadog-agent/cmd/security-agent/subcommands/check" | ||
"github.com/DataDog/datadog-agent/pkg/util/fxutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/DataDog/datadog-agent/cmd/security-agent/command" | ||
"github.com/DataDog/datadog-agent/comp/core" | ||
) | ||
|
||
// This test suite requires build flags because the check child command requires them. | ||
// go test ./cmd/security-agent/subcommands/compliance --tags=\!windows,kubeapiserver | ||
|
||
// TestCheckSubcommand ultimately uses the check package, so its dependencies are different from the event subcommand | ||
func TestCheckSubcommand(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cliInput []string | ||
check func(cliParams *check.CliParams, params core.BundleParams) | ||
}{ | ||
{ | ||
name: "compliance check", | ||
cliInput: []string{"compliance", "check"}, | ||
check: func(cliParams *check.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: "compliance check verbose", | ||
cliInput: []string{"compliance", "check", "--verbose"}, | ||
check: func(cliParams *check.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") | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
fxutil.TestOneShotSubcommand(t, | ||
Commands(&command.GlobalParams{}), | ||
test.cliInput, | ||
check.RunCheck, | ||
test.check, | ||
) | ||
} | ||
} | ||
|
||
func TestCommand_kubeapiserver(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cliInput []string | ||
check func(cliParams *cliParams, params core.BundleParams) | ||
}{ | ||
{ | ||
name: "compliance event tags", | ||
cliInput: []string{"compliance", "event", "--tags", "test:tag"}, | ||
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") | ||
require.Equal(t, []string{"test:tag"}, cliParams.event.Tags, "tags arg input not matching") | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
rootCommand := Commands(&command.GlobalParams{})[0] | ||
|
||
var subcommandNames []string | ||
for _, subcommand := range rootCommand.Commands() { | ||
subcommandNames = append(subcommandNames, subcommand.Use) | ||
} | ||
require.Equal(t, []string{"check", "event"}, subcommandNames, "subcommand missing") | ||
|
||
fxutil.TestOneShotSubcommand(t, | ||
Commands(&command.GlobalParams{}), | ||
test.cliInput, | ||
eventRun, | ||
test.check, | ||
) | ||
} | ||
} |
Oops, something went wrong.