mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-07 03:06:52 +00:00
Wrote ne tsts for the following packages: - completion - config - download - fix - list Also addressed a potential crash in the compleition, download, and list subcommands when no arguement was provided to the Args, RunE or Run functions. Updated `DownloadSupportCommands`, 'ListSupportActions' function to return sorted slice of strings. Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package list
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/kubescape/kubescape/v3/core/core"
|
|
"github.com/kubescape/kubescape/v3/core/mocks"
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetListCmd(t *testing.T) {
|
|
// Create a mock Kubescape interface
|
|
mockKubescape := &mocks.MockIKubescape{}
|
|
|
|
// Call the GetListCmd function
|
|
listCmd := GetListCmd(mockKubescape)
|
|
|
|
// Verify the command name and short description
|
|
assert.Equal(t, "list <policy> [flags]", listCmd.Use)
|
|
assert.Equal(t, "List frameworks/controls will list the supported frameworks and controls", listCmd.Short)
|
|
assert.Equal(t, "", listCmd.Long)
|
|
assert.Equal(t, listExample, listCmd.Example)
|
|
supported := strings.Join(core.ListSupportActions(), ",")
|
|
|
|
err := listCmd.Args(&cobra.Command{}, []string{})
|
|
expectedErrorMessage := "policy type requeued, supported: " + supported
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = listCmd.Args(&cobra.Command{}, []string{"not-frameworks"})
|
|
expectedErrorMessage = "invalid parameter 'not-frameworks'. Supported parameters: " + supported
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = listCmd.Args(&cobra.Command{}, []string{"frameworks"})
|
|
assert.Nil(t, err)
|
|
|
|
err = listCmd.RunE(&cobra.Command{}, []string{})
|
|
expectedErrorMessage = "no arguements provided"
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = listCmd.RunE(&cobra.Command{}, []string{"some-value"})
|
|
assert.Nil(t, err)
|
|
}
|