From 5172ce30d102a44b9418d7318995d4058536f97a Mon Sep 17 00:00:00 2001 From: Umair <58398786+Umair0343@users.noreply.github.com> Date: Sun, 26 Nov 2023 13:29:20 +0500 Subject: [PATCH] Update framework_test.go (Add Test Case for Non-Existent Framework in GetFrameworkCmd) Description: This pull request introduces a new test case TestGetFrameworkCmdWithNonExistentFramework in the framework_test.go file. The purpose of this test case is to verify the behavior of the getFrameworkCmd function when it's run with a non-existent framework argument. In this test case, we: Create a mock Kubescape interface and a ScanInfo object Call the getFrameworkCmd function with the mock interface and ScanInfo object Run the command with a non-existent framework 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 getFrameworkCmd function and ensures that it correctly handles non-existent framework arguments. Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com> --- cmd/scan/framework_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/scan/framework_test.go b/cmd/scan/framework_test.go index e2a3ef38..bf437b3c 100644 --- a/cmd/scan/framework_test.go +++ b/cmd/scan/framework_test.go @@ -39,3 +39,22 @@ func TestGetFrameworkCmd(t *testing.T) { expectedErrorMessage = "bad argument: accound ID must be a valid UUID" assert.Equal(t, expectedErrorMessage, err.Error()) } + +func TestGetFrameworkCmdWithNonExistentFramework(t *testing.T) { + // Create a mock Kubescape interface + mockKubescape := &mocks.MockIKubescape{} + scanInfo := cautils.ScanInfo{ + AccountID: "new", + } + + // Call the GetFrameworkCmd function + cmd := getFrameworkCmd(mockKubescape, &scanInfo) + + // Run the command with a non-existent framework argument + err := cmd.RunE(&cobra.Command{}, []string{"framework", "nsa,mitre"}) + + // 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()) +}