test: simplify allowed command checks using slices.Contains
This commit is contained in:
parent
0d63e18880
commit
c45811f2d9
3 changed files with 27 additions and 24 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -26,18 +27,18 @@ func TestNewAuthCommand(t *testing.T) {
|
|||
assert.False(t, cmd.HasFlags())
|
||||
assert.True(t, cmd.HasSubCommands())
|
||||
|
||||
allowedCommands := map[string]struct{}{
|
||||
"login": {},
|
||||
"logout": {},
|
||||
"status": {},
|
||||
"models": {},
|
||||
allowedCommands := []string{
|
||||
"login",
|
||||
"logout",
|
||||
"status",
|
||||
"models",
|
||||
}
|
||||
|
||||
subcommands := cmd.Commands()
|
||||
assert.Len(t, subcommands, len(allowedCommands))
|
||||
|
||||
for _, subcmd := range subcommands {
|
||||
_, found := allowedCommands[subcmd.Name()]
|
||||
found := slices.Contains(allowedCommands, subcmd.Name())
|
||||
assert.True(t, found, "unexpected subcommand %q", subcmd.Name())
|
||||
|
||||
assert.Len(t, subcmd.Aliases, 0)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package cron
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -28,19 +29,19 @@ func TestNewCronCommand(t *testing.T) {
|
|||
|
||||
assert.True(t, cmd.HasSubCommands())
|
||||
|
||||
allowedCommands := map[string]struct{}{
|
||||
"list": {},
|
||||
"add": {},
|
||||
"remove": {},
|
||||
"enable": {},
|
||||
"disable": {},
|
||||
allowedCommands := []string{
|
||||
"list",
|
||||
"add",
|
||||
"remove",
|
||||
"enable",
|
||||
"disable",
|
||||
}
|
||||
|
||||
subcommands := cmd.Commands()
|
||||
assert.Len(t, subcommands, len(allowedCommands))
|
||||
|
||||
for _, subcmd := range subcommands {
|
||||
_, found := allowedCommands[subcmd.Name()]
|
||||
found := slices.Contains(allowedCommands, subcmd.Name())
|
||||
assert.True(t, found, "unexpected subcommand %q", subcmd.Name())
|
||||
|
||||
assert.Len(t, subcmd.Aliases, 0)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -26,23 +27,23 @@ func TestNewPicoclawCommand(t *testing.T) {
|
|||
assert.Nil(t, cmd.PersistentPreRun)
|
||||
assert.Nil(t, cmd.PersistentPostRun)
|
||||
|
||||
allowedCommands := map[string]struct{}{
|
||||
"agent": {},
|
||||
"auth": {},
|
||||
"cron": {},
|
||||
"gateway": {},
|
||||
"migrate": {},
|
||||
"onboard": {},
|
||||
"skills": {},
|
||||
"status": {},
|
||||
"version": {},
|
||||
allowedCommands := []string{
|
||||
"agent",
|
||||
"auth",
|
||||
"cron",
|
||||
"gateway",
|
||||
"migrate",
|
||||
"onboard",
|
||||
"skills",
|
||||
"status",
|
||||
"version",
|
||||
}
|
||||
|
||||
subcommands := cmd.Commands()
|
||||
assert.Len(t, subcommands, len(allowedCommands))
|
||||
|
||||
for _, subcmd := range subcommands {
|
||||
_, found := allowedCommands[subcmd.Name()]
|
||||
found := slices.Contains(allowedCommands, subcmd.Name())
|
||||
assert.True(t, found, "unexpected subcommand %q", subcmd.Name())
|
||||
|
||||
assert.False(t, subcmd.Hidden)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue