mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 18:09:55 +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>
36 lines
993 B
Go
36 lines
993 B
Go
package scan
|
|
|
|
import (
|
|
"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 TestGetImageCmd(t *testing.T) {
|
|
// Create a mock Kubescape interface
|
|
mockKubescape := &mocks.MockIKubescape{}
|
|
scanInfo := cautils.ScanInfo{
|
|
AccountID: "new",
|
|
}
|
|
|
|
cmd := getImageCmd(mockKubescape, &scanInfo)
|
|
|
|
// Verify the command name and short description
|
|
assert.Equal(t, "image <image>:<tag> [flags]", cmd.Use)
|
|
assert.Equal(t, "Scan an image for vulnerabilities", cmd.Short)
|
|
assert.Equal(t, imageExample, cmd.Example)
|
|
|
|
err := cmd.Args(&cobra.Command{}, []string{})
|
|
expectedErrorMessage := "the command takes exactly one image name as an argument"
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
|
|
err = cmd.Args(&cobra.Command{}, []string{"nginx"})
|
|
assert.Nil(t, err)
|
|
|
|
err = cmd.RunE(&cobra.Command{}, []string{})
|
|
assert.Equal(t, expectedErrorMessage, err.Error())
|
|
}
|