mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 18:09:55 +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>
31 lines
894 B
Go
31 lines
894 B
Go
package fix
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kubescape/kubescape/v3/core/mocks"
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetFixCmd(t *testing.T) {
|
|
// Create a mock Kubescape interface
|
|
mockKubescape := &mocks.MockIKubescape{}
|
|
|
|
// Call the GetFixCmd function
|
|
fixCmd := GetFixCmd(mockKubescape)
|
|
|
|
// Verify the command name and short description
|
|
assert.Equal(t, "fix <report output file>", fixCmd.Use)
|
|
assert.Equal(t, "Propose a fix for the misconfiguration found when scanning Kubernetes manifest files", fixCmd.Short)
|
|
assert.Equal(t, "", fixCmd.Long)
|
|
assert.Equal(t, fixCmdExamples, fixCmd.Example)
|
|
|
|
err := fixCmd.RunE(&cobra.Command{}, []string{})
|
|
expectedErrorMessage := "report output file is required"
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = fixCmd.RunE(&cobra.Command{}, []string{"random-file.json"})
|
|
assert.Nil(t, err)
|
|
}
|