mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 18:09:55 +00:00
Update control_test.go (Add Test Case for Non-Existent Control in GetControlCmd)
Description: This pull request introduces a new test case TestGetControlCmdWithNonExistentControl in the control_test.go file. The purpose of this test case is to verify the behavior of the getControlCmd function when it's run with a non-existent control argument. In this test case, we: Create a mock Kubescape interface and a ScanInfo object Call the getControlCmd function with the mock interface and ScanInfo object Run the command with a non-existent control argument Check that there is an error and the error message is "bad argument: account ID must be a valid UUID" This test case enhances the test coverage of the getControlCmd function and ensures that it correctly handles non-existent control arguments. Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
This commit is contained in:
@@ -39,3 +39,22 @@ func TestGetControlCmd(t *testing.T) {
|
||||
expectedErrorMessage = "bad argument: accound ID must be a valid UUID"
|
||||
assert.Equal(t, expectedErrorMessage, err.Error())
|
||||
}
|
||||
|
||||
func TestGetControlCmdWithNonExistentControl(t *testing.T) {
|
||||
// Create a mock Kubescape interface
|
||||
mockKubescape := &mocks.MockIKubescape{}
|
||||
scanInfo := cautils.ScanInfo{
|
||||
AccountID: "new",
|
||||
}
|
||||
|
||||
// Call the GetControlCmd function
|
||||
cmd := getControlCmd(mockKubescape, &scanInfo)
|
||||
|
||||
// Run the command with a non-existent control argument
|
||||
err := cmd.RunE(&cobra.Command{}, []string{"control", "C-0001,C-0002"})
|
||||
|
||||
// Check that there is an error and the error message is as expected
|
||||
expectedErrorMessage := "bad argument: accound ID must be a valid UUID"
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, expectedErrorMessage, err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user