mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 18:09:55 +00:00
Wrote new tests for the following packages in the cmd package:
- completion
- config
* In addition to tests, updated the code for the `stringKeysToSlice`
to return the final string slice in sorted order of keys.
Added new MockIKubescape struct in the core/mocks package
Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/kubescape/kubescape/v3/core/mocks"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetConfigCmd(t *testing.T) {
|
|
// Create a mock Kubescape interface
|
|
mockKubescape := &mocks.MockIKubescape{}
|
|
|
|
// Call the GetConfigCmd function
|
|
configCmd := GetConfigCmd(mockKubescape)
|
|
|
|
// Verify the command name and short description
|
|
assert.Equal(t, "config", configCmd.Use)
|
|
assert.Equal(t, "Handle cached configurations", configCmd.Short)
|
|
assert.Equal(t, configExample, configCmd.Example)
|
|
|
|
// Verify that the subcommands are added correctly
|
|
assert.Equal(t, 3, len(configCmd.Commands()))
|
|
|
|
for _, subcmd := range configCmd.Commands() {
|
|
switch subcmd.Name() {
|
|
case "delete":
|
|
// Verify that the delete subcommand is added correctly
|
|
assert.Equal(t, "delete", subcmd.Use)
|
|
assert.Equal(t, "Delete cached configurations", subcmd.Short)
|
|
case "set":
|
|
// Verify that the set subcommand is added correctly
|
|
assert.Equal(t, "set", subcmd.Use)
|
|
assert.Equal(t, "Set configurations, supported: "+strings.Join(stringKeysToSlice(supportConfigSet), "/"), subcmd.Short)
|
|
case "view":
|
|
// Verify that the view subcommand is added correctly
|
|
assert.Equal(t, "view", subcmd.Use)
|
|
assert.Equal(t, "View cached configurations", subcmd.Short)
|
|
default:
|
|
t.Errorf("Unexpected subcommand name: %s", subcmd.Name())
|
|
}
|
|
}
|
|
}
|