mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
Wrote new tests for the following packages - operator - patch - scan Also fixed potential crash in the RunE function of the image subcommand in the scan package. Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package scan
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/kubescape/kubescape/v3/core/cautils"
|
|
"github.com/kubescape/kubescape/v3/core/mocks"
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetFrameworkCmd(t *testing.T) {
|
|
// Create a mock Kubescape interface
|
|
mockKubescape := &mocks.MockIKubescape{}
|
|
scanInfo := cautils.ScanInfo{
|
|
AccountID: "new",
|
|
}
|
|
|
|
cmd := getFrameworkCmd(mockKubescape, &scanInfo)
|
|
|
|
// Verify the command name and short description
|
|
assert.Equal(t, "framework <framework names list> [`<glob pattern>`/`-`] [flags]", cmd.Use)
|
|
assert.Equal(t, fmt.Sprintf("The framework you wish to use. Run '%[1]s list frameworks' for the list of supported frameworks", cautils.ExecName()), cmd.Short)
|
|
assert.Equal(t, frameworkExample, cmd.Example)
|
|
|
|
err := cmd.Args(&cobra.Command{}, []string{})
|
|
expectedErrorMessage := "requires at least one framework name"
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = cmd.Args(&cobra.Command{}, []string{"nsa,mitre"})
|
|
assert.Nil(t, err)
|
|
|
|
err = cmd.Args(&cobra.Command{}, []string{"nsa,mitre,"})
|
|
expectedErrorMessage = "usage: <framework-0>,<framework-1>"
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = cmd.RunE(&cobra.Command{}, []string{})
|
|
expectedErrorMessage = "bad argument: accound ID must be a valid UUID"
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
}
|