test: migrate command tests to testify assertions
Replace standard library testing error checks (t.Error*, t.Fatalf) with assert/require from stretchr/testify across all cobra command tests for improved readability and consistency.
This commit is contained in:
parent
e7716cc989
commit
c857dcb03e
28 changed files with 437 additions and 912 deletions
|
|
@ -1,63 +1,33 @@
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewAgentCommand(t *testing.T) {
|
func TestNewAgentCommand(t *testing.T) {
|
||||||
cmd := NewAgentCommand()
|
cmd := NewAgentCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "agent" {
|
assert.Equal(t, "agent", cmd.Use)
|
||||||
t.Errorf("expected command name 'agent', got %q", cmd.Use)
|
assert.Equal(t, "Interact with the agent directly", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Interact with the agent directly" {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
assert.NotNil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Error("expected command to have no subcommands")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have nil Run()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
assert.NotNil(t, cmd.Flags().Lookup("debug"))
|
||||||
t.Error("expected command to have non-nil RunE()")
|
assert.NotNil(t, cmd.Flags().Lookup("message"))
|
||||||
}
|
assert.NotNil(t, cmd.Flags().Lookup("session"))
|
||||||
|
assert.NotNil(t, cmd.Flags().Lookup("model"))
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("debug") == nil {
|
|
||||||
t.Error("expected command to have debug flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("message") == nil {
|
|
||||||
t.Error("expected command to have message flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("session") == nil {
|
|
||||||
t.Error("expected command to have session flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("model") == nil {
|
|
||||||
t.Error("expected command to have model flag")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,30 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewAuthCommand(t *testing.T) {
|
func TestNewAuthCommand(t *testing.T) {
|
||||||
cmd := NewAuthCommand()
|
cmd := NewAuthCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "auth" {
|
assert.Equal(t, "auth", cmd.Use)
|
||||||
t.Errorf("expected command name 'auth', got %q", cmd.Use)
|
assert.Equal(t, "Manage authentication (login, logout, status)", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Manage authentication (login, logout, status)" {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
assert.NotNil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Error("expected command to have nil Run()")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have non-nil RunE()")
|
assert.True(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasSubCommands() {
|
|
||||||
t.Error("expected command to have subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
allowedCommands := map[string]struct{}{
|
allowedCommands := map[string]struct{}{
|
||||||
"login": {},
|
"login": {},
|
||||||
|
|
@ -52,37 +33,22 @@ func TestNewAuthCommand(t *testing.T) {
|
||||||
"models": {},
|
"models": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, subcmd := range cmd.Commands() {
|
subcommands := cmd.Commands()
|
||||||
if _, found := allowedCommands[subcmd.Name()]; !found {
|
assert.Len(t, subcommands, len(allowedCommands))
|
||||||
t.Errorf("unexpected subcommand %q", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(subcmd.Aliases) > 0 {
|
for _, subcmd := range subcommands {
|
||||||
t.Errorf("expected subcommand %q to have no aliases, got %d", subcmd.Name(), len(subcmd.Aliases))
|
_, found := allowedCommands[subcmd.Name()]
|
||||||
}
|
assert.True(t, found, "unexpected subcommand %q", subcmd.Name())
|
||||||
|
|
||||||
if cmd.Hidden {
|
assert.Len(t, subcmd.Aliases, 0)
|
||||||
t.Errorf("expected subcommand %q to be visible", subcmd.Name())
|
assert.False(t, subcmd.Hidden)
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.HasSubCommands() {
|
assert.False(t, subcmd.HasSubCommands())
|
||||||
t.Errorf("expected subcommand `%s` to have no subcommands", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.Run != nil {
|
assert.Nil(t, subcmd.Run)
|
||||||
t.Errorf("expected subcommand `%s` to have nil Run()", subcmd.Name())
|
assert.NotNil(t, subcmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.RunE == nil {
|
assert.Nil(t, subcmd.PersistentPreRun)
|
||||||
t.Errorf("expected subcommand `%s` to have non-nil RunE()", subcmd.Name())
|
assert.Nil(t, subcmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.PersistentPreRun != nil {
|
|
||||||
t.Errorf("expected subcommand `%s` to have nil PersistentPreRun()", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.PersistentPostRun != nil {
|
|
||||||
t.Errorf("expected subcommand `%s` to have nil PersistentPostRun()", subcmd.Name())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,39 +4,26 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewLoginSubCommand(t *testing.T) {
|
func TestNewLoginSubCommand(t *testing.T) {
|
||||||
cmd := newLoginCommand()
|
cmd := newLoginCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Login via OAuth or paste token" {
|
assert.Equal(t, "Login via OAuth or paste token", cmd.Short)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("device-code") == nil {
|
assert.NotNil(t, cmd.Flags().Lookup("device-code"))
|
||||||
t.Error("expected command to have device-code flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
hasProviderFlag := cmd.Flags().Lookup("provider") != nil
|
providerFlag := cmd.Flags().Lookup("provider")
|
||||||
if !hasProviderFlag {
|
require.NotNil(t, providerFlag)
|
||||||
t.Error("expected command to have provider flag")
|
|
||||||
} else {
|
|
||||||
var val []string
|
|
||||||
var found bool
|
|
||||||
providerFlag := cmd.Flag("provider")
|
|
||||||
|
|
||||||
val, found = providerFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
val, found := providerFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
||||||
|
require.True(t, found)
|
||||||
if !found || val[0] != "true" {
|
require.NotEmpty(t, val)
|
||||||
t.Errorf("expected provider flag to be required, got %v", val)
|
assert.Equal(t, "true", val[0])
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,20 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewLogoutSubcommand(t *testing.T) {
|
func TestNewLogoutSubcommand(t *testing.T) {
|
||||||
cmd := newLogoutCommand()
|
cmd := newLogoutCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Remove stored credentials" {
|
assert.Equal(t, "Remove stored credentials", cmd.Short)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("provider") == nil {
|
assert.NotNil(t, cmd.Flags().Lookup("provider"))
|
||||||
t.Error("expected command to have provider flag")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,19 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewModelsCommand(t *testing.T) {
|
func TestNewModelsCommand(t *testing.T) {
|
||||||
cmd := newModelsCommand()
|
cmd := newModelsCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "models" {
|
assert.Equal(t, "models", cmd.Use)
|
||||||
t.Errorf("expected command name 'models', got %q", cmd.Use)
|
assert.Equal(t, "Show available models", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Show available models" {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewStatusSubcommand(t *testing.T) {
|
func TestNewStatusSubcommand(t *testing.T) {
|
||||||
cmd := newStatusCommand()
|
cmd := newStatusCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Show current auth status" {
|
assert.Equal(t, "Show current auth status", cmd.Short)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,80 +4,40 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewAddSubcommand(t *testing.T) {
|
func TestNewAddSubcommand(t *testing.T) {
|
||||||
fn := func() string { return "" }
|
fn := func() string { return "" }
|
||||||
cmd := newAddCommand(fn)
|
cmd := newAddCommand(fn)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "add" {
|
assert.Equal(t, "add", cmd.Use)
|
||||||
t.Errorf("expected command name 'add', got %q", cmd.Use)
|
assert.Equal(t, "Add a new scheduled job", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Add a new scheduled job" {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
assert.NotNil(t, cmd.Flags().Lookup("every"))
|
||||||
t.Error("expected command to have flags")
|
assert.NotNil(t, cmd.Flags().Lookup("cron"))
|
||||||
}
|
assert.NotNil(t, cmd.Flags().Lookup("deliver"))
|
||||||
|
assert.NotNil(t, cmd.Flags().Lookup("to"))
|
||||||
|
assert.NotNil(t, cmd.Flags().Lookup("channel"))
|
||||||
|
|
||||||
if cmd.Flags().Lookup("every") == nil {
|
nameFlag := cmd.Flags().Lookup("name")
|
||||||
t.Error("expected command to have every flag")
|
require.NotNil(t, nameFlag)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("cron") == nil {
|
messageFlag := cmd.Flags().Lookup("message")
|
||||||
t.Error("expected command to have cron flag")
|
require.NotNil(t, messageFlag)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("deliver") == nil {
|
val, found := nameFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
||||||
t.Error("expected command to have deliver flag")
|
require.True(t, found)
|
||||||
}
|
require.NotEmpty(t, val)
|
||||||
|
assert.Equal(t, "true", val[0])
|
||||||
if cmd.Flags().Lookup("to") == nil {
|
|
||||||
t.Error("expected command to have to flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("channel") == nil {
|
|
||||||
t.Error("expected command to have channel flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
hasNameFlag := cmd.Flags().Lookup("name") != nil
|
|
||||||
hasMessageFlag := cmd.Flags().Lookup("message") != nil
|
|
||||||
|
|
||||||
if !hasNameFlag {
|
|
||||||
t.Error("expected command to have name flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasMessageFlag {
|
|
||||||
t.Error("expected command to have message flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if hasNameFlag {
|
|
||||||
var val []string
|
|
||||||
var found bool
|
|
||||||
nameFlag := cmd.Flag("name")
|
|
||||||
|
|
||||||
val, found = nameFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
|
||||||
|
|
||||||
if !found || val[0] != "true" {
|
|
||||||
t.Errorf("expected name flag to be required, got %v", val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if hasMessageFlag {
|
|
||||||
var val []string
|
|
||||||
var found bool
|
|
||||||
messageFlag := cmd.Flag("message")
|
|
||||||
|
|
||||||
val, found = messageFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
val, found = messageFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
||||||
|
require.True(t, found)
|
||||||
if !found || val[0] != "true" {
|
require.NotEmpty(t, val)
|
||||||
t.Errorf("expected message flag to be required, got %v", val)
|
assert.Equal(t, "true", val[0])
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,32 @@
|
||||||
package cron
|
package cron
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewCronCommand(t *testing.T) {
|
func TestNewCronCommand(t *testing.T) {
|
||||||
cmd := NewCronCommand()
|
cmd := NewCronCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Manage scheduled tasks" {
|
assert.Equal(t, "Manage scheduled tasks", cmd.Short)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) != 1 {
|
assert.Len(t, cmd.Aliases, 1)
|
||||||
t.Errorf("expected command to have exactly one alias, got %d", len(cmd.Aliases))
|
assert.True(t, cmd.HasAlias("c"))
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("c") {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Errorf("expected command to have alias `c`, got %v", cmd.Aliases)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Error("expected command to have no flags")
|
assert.NotNil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
assert.NotNil(t, cmd.PersistentPreRunE)
|
||||||
t.Error("expected command to have nil Run()")
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
}
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
assert.True(t, cmd.HasSubCommands())
|
||||||
t.Error("expected command to have non-nil RunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRunE == nil {
|
|
||||||
t.Error("expected command to have non-nil PersistentPreRunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasSubCommands() {
|
|
||||||
t.Error("expected command to have subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
allowedCommands := map[string]struct{}{
|
allowedCommands := map[string]struct{}{
|
||||||
"list": {},
|
"list": {},
|
||||||
|
|
@ -57,37 +36,22 @@ func TestNewCronCommand(t *testing.T) {
|
||||||
"disable": {},
|
"disable": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, subcmd := range cmd.Commands() {
|
subcommands := cmd.Commands()
|
||||||
if _, found := allowedCommands[subcmd.Name()]; !found {
|
assert.Len(t, subcommands, len(allowedCommands))
|
||||||
t.Errorf("unexpected subcommand %q", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(subcmd.Aliases) > 0 {
|
for _, subcmd := range subcommands {
|
||||||
t.Errorf("expected subcommand %q to have no aliases, got %d", subcmd.Name(), len(subcmd.Aliases))
|
_, found := allowedCommands[subcmd.Name()]
|
||||||
}
|
assert.True(t, found, "unexpected subcommand %q", subcmd.Name())
|
||||||
|
|
||||||
if cmd.Hidden {
|
assert.Len(t, subcmd.Aliases, 0)
|
||||||
t.Errorf("expected subcommand %q to be visible", subcmd.Name())
|
assert.False(t, subcmd.Hidden)
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.HasSubCommands() {
|
assert.False(t, subcmd.HasSubCommands())
|
||||||
t.Errorf("expected subcommand `%s` to have no subcommands", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.Run != nil {
|
assert.Nil(t, subcmd.Run)
|
||||||
t.Errorf("expected subcommand `%s` to have nil Run()", subcmd.Name())
|
assert.NotNil(t, subcmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.RunE == nil {
|
assert.Nil(t, subcmd.PersistentPreRun)
|
||||||
t.Errorf("expected subcommand `%s` to have non-nil RunE()", subcmd.Name())
|
assert.Nil(t, subcmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.PersistentPreRun != nil {
|
|
||||||
t.Errorf("expected subcommand `%s` to have nil PersistentPreRun()", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if subcmd.PersistentPostRun != nil {
|
|
||||||
t.Errorf("expected subcommand `%s` to have nil PersistentPostRun()", subcmd.Name())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,20 @@
|
||||||
package cron
|
package cron
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestDisableSubcommand(t *testing.T) {
|
func TestDisableSubcommand(t *testing.T) {
|
||||||
fn := func() string { return "" }
|
fn := func() string { return "" }
|
||||||
cmd := newDisableCommand(fn)
|
cmd := newDisableCommand(fn)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "disable" {
|
assert.Equal(t, "disable", cmd.Use)
|
||||||
t.Errorf("expected command name 'disable', got %q", cmd.Use)
|
assert.Equal(t, "Disable a job", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Disable a job" {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,20 @@
|
||||||
package cron
|
package cron
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestEnableSubcommand(t *testing.T) {
|
func TestEnableSubcommand(t *testing.T) {
|
||||||
fn := func() string { return "" }
|
fn := func() string { return "" }
|
||||||
cmd := newEnableCommand(fn)
|
cmd := newEnableCommand(fn)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "enable" {
|
assert.Equal(t, "enable", cmd.Use)
|
||||||
t.Errorf("expected command name 'enable', got %q", cmd.Use)
|
assert.Equal(t, "Enable a job", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Enable a job" {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
package cron
|
package cron
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewListSubcommand(t *testing.T) {
|
func TestNewListSubcommand(t *testing.T) {
|
||||||
fn := func() string { return "" }
|
fn := func() string { return "" }
|
||||||
cmd := newListCommand(fn)
|
cmd := newListCommand(fn)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "List all scheduled jobs" {
|
assert.Equal(t, "List all scheduled jobs", cmd.Short)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,19 @@
|
||||||
package cron
|
package cron
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewRemoveSubcommand(t *testing.T) {
|
func TestNewRemoveSubcommand(t *testing.T) {
|
||||||
fn := func() string { return "" }
|
fn := func() string { return "" }
|
||||||
cmd := newRemoveCommand(fn)
|
cmd := newRemoveCommand(fn)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Remove a job by ID" {
|
assert.Equal(t, "Remove a job by ID", cmd.Short)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,55 +1,31 @@
|
||||||
package gateway
|
package gateway
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewGatewayCommand(t *testing.T) {
|
func TestNewGatewayCommand(t *testing.T) {
|
||||||
cmd := NewGatewayCommand()
|
cmd := NewGatewayCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "gateway" {
|
assert.Equal(t, "gateway", cmd.Use)
|
||||||
t.Errorf("expected command name 'gateway', got %q", cmd.Use)
|
assert.Equal(t, "Start picoclaw gateway", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Start picoclaw gateway" {
|
assert.Len(t, cmd.Aliases, 1)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
assert.True(t, cmd.HasAlias("g"))
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) != 1 {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Errorf("expected command to have 1 alias, got %d", len(cmd.Aliases))
|
assert.NotNil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("g") {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Errorf("expected command to have alias 'g'")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
assert.False(t, cmd.HasSubCommands())
|
||||||
t.Error("expected command to have nil Run()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have non-nil RunE()")
|
assert.NotNil(t, cmd.Flags().Lookup("debug"))
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("debug") == nil {
|
|
||||||
t.Error("expected command to have debug flag")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetConfigPath(t *testing.T) {
|
func TestGetConfigPath(t *testing.T) {
|
||||||
|
|
@ -13,107 +16,66 @@ func TestGetConfigPath(t *testing.T) {
|
||||||
got := GetConfigPath()
|
got := GetConfigPath()
|
||||||
want := filepath.Join("/tmp/home", ".picoclaw", "config.json")
|
want := filepath.Join("/tmp/home", ".picoclaw", "config.json")
|
||||||
|
|
||||||
if got != want {
|
assert.Equal(t, want, got)
|
||||||
t.Fatalf("GetConfigPath() = %q, want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatVersion_NoGitCommit(t *testing.T) {
|
func TestFormatVersion_NoGitCommit(t *testing.T) {
|
||||||
oldVersion, oldGit := version, gitCommit
|
oldVersion, oldGit := version, gitCommit
|
||||||
|
t.Cleanup(func() { version, gitCommit = oldVersion, oldGit })
|
||||||
t.Cleanup(func() {
|
|
||||||
version, gitCommit = oldVersion, oldGit
|
|
||||||
})
|
|
||||||
|
|
||||||
version = "1.2.3"
|
version = "1.2.3"
|
||||||
gitCommit = ""
|
gitCommit = ""
|
||||||
|
|
||||||
got := FormatVersion()
|
assert.Equal(t, "1.2.3", FormatVersion())
|
||||||
want := "1.2.3"
|
|
||||||
|
|
||||||
if got != want {
|
|
||||||
t.Fatalf("FormatVersion() = %q, want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatVersion_WithGitCommit(t *testing.T) {
|
func TestFormatVersion_WithGitCommit(t *testing.T) {
|
||||||
oldVersion, oldGit := version, gitCommit
|
oldVersion, oldGit := version, gitCommit
|
||||||
|
t.Cleanup(func() { version, gitCommit = oldVersion, oldGit })
|
||||||
t.Cleanup(func() {
|
|
||||||
version, gitCommit = oldVersion, oldGit
|
|
||||||
})
|
|
||||||
|
|
||||||
version = "1.2.3"
|
version = "1.2.3"
|
||||||
gitCommit = "abc123"
|
gitCommit = "abc123"
|
||||||
|
|
||||||
got := FormatVersion()
|
assert.Equal(t, "1.2.3 (git: abc123)", FormatVersion())
|
||||||
want := "1.2.3 (git: abc123)"
|
|
||||||
|
|
||||||
if got != want {
|
|
||||||
t.Fatalf("FormatVersion() = %q, want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatBuildInfo_UsesBuildTimeAndGoVersion_WhenSet(t *testing.T) {
|
func TestFormatBuildInfo_UsesBuildTimeAndGoVersion_WhenSet(t *testing.T) {
|
||||||
oldBuildTime, oldGoVersion := buildTime, goVersion
|
oldBuildTime, oldGoVersion := buildTime, goVersion
|
||||||
|
t.Cleanup(func() { buildTime, goVersion = oldBuildTime, oldGoVersion })
|
||||||
t.Cleanup(func() {
|
|
||||||
buildTime, goVersion = oldBuildTime, oldGoVersion
|
|
||||||
})
|
|
||||||
|
|
||||||
buildTime = "2026-02-20T00:00:00Z"
|
buildTime = "2026-02-20T00:00:00Z"
|
||||||
goVersion = "go1.23.0"
|
goVersion = "go1.23.0"
|
||||||
|
|
||||||
build, goVer := FormatBuildInfo()
|
build, goVer := FormatBuildInfo()
|
||||||
|
|
||||||
if build != buildTime {
|
assert.Equal(t, buildTime, build)
|
||||||
t.Fatalf("FormatBuildInfo().build = %q, want %q", build, buildTime)
|
assert.Equal(t, goVersion, goVer)
|
||||||
}
|
|
||||||
|
|
||||||
if goVer != goVersion {
|
|
||||||
t.Fatalf("FormatBuildInfo().goVer = %q, want %q", goVer, goVersion)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatBuildInfo_EmptyBuildTime_ReturnsEmptyBuild(t *testing.T) {
|
func TestFormatBuildInfo_EmptyBuildTime_ReturnsEmptyBuild(t *testing.T) {
|
||||||
oldBuildTime, oldGoVersion := buildTime, goVersion
|
oldBuildTime, oldGoVersion := buildTime, goVersion
|
||||||
|
t.Cleanup(func() { buildTime, goVersion = oldBuildTime, oldGoVersion })
|
||||||
t.Cleanup(func() {
|
|
||||||
buildTime, goVersion = oldBuildTime, oldGoVersion
|
|
||||||
})
|
|
||||||
|
|
||||||
buildTime = ""
|
buildTime = ""
|
||||||
goVersion = "go1.23.0"
|
goVersion = "go1.23.0"
|
||||||
|
|
||||||
build, goVer := FormatBuildInfo()
|
build, goVer := FormatBuildInfo()
|
||||||
|
|
||||||
if build != "" {
|
assert.Empty(t, build)
|
||||||
t.Fatalf("FormatBuildInfo().build = %q, want empty", build)
|
assert.Equal(t, goVersion, goVer)
|
||||||
}
|
|
||||||
|
|
||||||
if goVer != goVersion {
|
|
||||||
t.Fatalf("FormatBuildInfo().goVer = %q, want %q", goVer, goVersion)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatBuildInfo_EmptyGoVersion_FallsBackToRuntimeVersion(t *testing.T) {
|
func TestFormatBuildInfo_EmptyGoVersion_FallsBackToRuntimeVersion(t *testing.T) {
|
||||||
oldBuildTime, oldGoVersion := buildTime, goVersion
|
oldBuildTime, oldGoVersion := buildTime, goVersion
|
||||||
|
t.Cleanup(func() { buildTime, goVersion = oldBuildTime, oldGoVersion })
|
||||||
t.Cleanup(func() {
|
|
||||||
buildTime, goVersion = oldBuildTime, oldGoVersion
|
|
||||||
})
|
|
||||||
|
|
||||||
buildTime = "x"
|
buildTime = "x"
|
||||||
goVersion = ""
|
goVersion = ""
|
||||||
|
|
||||||
build, goVer := FormatBuildInfo()
|
build, goVer := FormatBuildInfo()
|
||||||
if build != "x" {
|
|
||||||
t.Fatalf("FormatBuildInfo().build = %q, want %q", build, "x")
|
|
||||||
}
|
|
||||||
|
|
||||||
if goVer != runtime.Version() {
|
assert.Equal(t, "x", build)
|
||||||
t.Fatalf("FormatBuildInfo().goVer = %q, want runtime.Version()=%q", goVer, runtime.Version())
|
assert.Equal(t, runtime.Version(), goVer)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetConfigPath_Windows(t *testing.T) {
|
func TestGetConfigPath_Windows(t *testing.T) {
|
||||||
|
|
@ -126,7 +88,5 @@ func TestGetConfigPath_Windows(t *testing.T) {
|
||||||
got := GetConfigPath()
|
got := GetConfigPath()
|
||||||
want := filepath.Join(`C:\Users\Test`, ".picoclaw", "config.json")
|
want := filepath.Join(`C:\Users\Test`, ".picoclaw", "config.json")
|
||||||
|
|
||||||
if !strings.EqualFold(got, want) {
|
require.True(t, strings.EqualFold(got, want), "GetConfigPath() = %q, want %q", got, want)
|
||||||
t.Fatalf("GetConfigPath() = %q, want %q", got, want)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,79 +1,38 @@
|
||||||
package migrate
|
package migrate
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewMigrateCommand(t *testing.T) {
|
func TestNewMigrateCommand(t *testing.T) {
|
||||||
cmd := NewMigrateCommand()
|
cmd := NewMigrateCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "migrate" {
|
assert.Equal(t, "migrate", cmd.Use)
|
||||||
t.Errorf("expected command name 'migrate', got %q", cmd.Use)
|
assert.Equal(t, "Migrate from OpenClaw to PicoClaw", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Migrate from OpenClaw to PicoClaw" {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Error("expected command to have example")
|
assert.NotNil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Error("expected command to have no subcommands")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have nil Run()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
assert.NotNil(t, cmd.Flags().Lookup("dry-run"))
|
||||||
t.Error("expected command to have non-nil RunE()")
|
assert.NotNil(t, cmd.Flags().Lookup("refresh"))
|
||||||
}
|
assert.NotNil(t, cmd.Flags().Lookup("config-only"))
|
||||||
|
assert.NotNil(t, cmd.Flags().Lookup("workspace-only"))
|
||||||
if cmd.PersistentPreRun != nil {
|
assert.NotNil(t, cmd.Flags().Lookup("force"))
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
assert.NotNil(t, cmd.Flags().Lookup("openclaw-home"))
|
||||||
}
|
assert.NotNil(t, cmd.Flags().Lookup("picoclaw-home"))
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("dry-run") == nil {
|
|
||||||
t.Error("expected command to have dry-run flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("refresh") == nil {
|
|
||||||
t.Error("expected command to have refresh flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("config-only") == nil {
|
|
||||||
t.Error("expected command to have config-only flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("workspace-only") == nil {
|
|
||||||
t.Error("expected command to have workspace-only flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("force") == nil {
|
|
||||||
t.Error("expected command to have force flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("openclaw-home") == nil {
|
|
||||||
t.Error("expected command to have openclaw-home flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("picoclaw-home") == nil {
|
|
||||||
t.Error("expected command to have picoclaw-home flag")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,29 @@
|
||||||
package onboard
|
package onboard
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewOnboardCommand(t *testing.T) {
|
func TestNewOnboardCommand(t *testing.T) {
|
||||||
cmd := NewOnboardCommand()
|
cmd := NewOnboardCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "onboard" {
|
assert.Equal(t, "onboard", cmd.Use)
|
||||||
t.Errorf("expected command name 'onboard', got %q", cmd.Use)
|
assert.Equal(t, "Initialize picoclaw configuration and workspace", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Initialize picoclaw configuration and workspace" {
|
assert.Len(t, cmd.Aliases, 1)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
assert.True(t, cmd.HasAlias("o"))
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) != 1 {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command to have 1 alias, got %d", len(cmd.Aliases))
|
assert.Nil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("o") {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Errorf("expected command to have alias 'o'")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE != nil {
|
|
||||||
t.Error("expected command to have nil RunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
cmd/picoclaw/internal/skills/command_test.go
Normal file
28
cmd/picoclaw/internal/skills/command_test.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package skills
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewSkillsCommand(t *testing.T) {
|
||||||
|
cmd := NewSkillsCommand()
|
||||||
|
|
||||||
|
require.NotNil(t, cmd)
|
||||||
|
|
||||||
|
assert.Equal(t, "skills", cmd.Use)
|
||||||
|
assert.Equal(t, "Manage skills", cmd.Short)
|
||||||
|
|
||||||
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
|
|
||||||
|
assert.False(t, cmd.HasFlags())
|
||||||
|
|
||||||
|
assert.Nil(t, cmd.Run)
|
||||||
|
assert.NotNil(t, cmd.RunE)
|
||||||
|
|
||||||
|
assert.NotNil(t, cmd.PersistentPreRunE)
|
||||||
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
|
}
|
||||||
|
|
@ -1,47 +1,28 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewInstallSubcommand(t *testing.T) {
|
func TestNewInstallSubcommand(t *testing.T) {
|
||||||
cmd := newInstallCommand(nil)
|
cmd := newInstallCommand(nil)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "install" {
|
assert.Equal(t, "install", cmd.Use)
|
||||||
t.Errorf("expected command name 'install', got %q", cmd.Use)
|
assert.Equal(t, "Install skill from GitHub", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Install skill from GitHub" {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
assert.NotNil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have nil RunE()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
assert.True(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.NotNil(t, cmd.Flags().Lookup("registry"))
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Flags().Lookup("registry") == nil {
|
|
||||||
t.Error("expected command to have registry flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,26 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewInstallbuiltinSubcommand(t *testing.T) {
|
func TestNewInstallbuiltinSubcommand(t *testing.T) {
|
||||||
cmd := newInstallBuiltinCommand("")
|
cmd := newInstallBuiltinCommand("")
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "install-builtin" {
|
assert.Equal(t, "install-builtin", cmd.Use)
|
||||||
t.Errorf("expected command name 'install-builtin', got %q", cmd.Use)
|
assert.Equal(t, "Install all builtin skills to workspace", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Install all builtin skills to workspace" {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,26 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewListSubcommand(t *testing.T) {
|
func TestNewListSubcommand(t *testing.T) {
|
||||||
cmd := newListCommand(nil)
|
cmd := newListCommand(nil)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "list" {
|
assert.Equal(t, "list", cmd.Use)
|
||||||
t.Errorf("expected command name 'list', got %q", cmd.Use)
|
assert.Equal(t, "List installed skills", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "List installed skills" {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,26 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewListbuiltinSubcommand(t *testing.T) {
|
func TestNewListbuiltinSubcommand(t *testing.T) {
|
||||||
cmd := newListBuiltinCommand()
|
cmd := newListBuiltinCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "list-builtin" {
|
assert.Equal(t, "list-builtin", cmd.Use)
|
||||||
t.Errorf("expected command name 'list-builtin', got %q", cmd.Use)
|
assert.Equal(t, "List available builtin skills", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "List available builtin skills" {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,28 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewRemoveSubcommand(t *testing.T) {
|
func TestNewRemoveSubcommand(t *testing.T) {
|
||||||
cmd := newRemoveCommand(nil)
|
cmd := newRemoveCommand(nil)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "remove" {
|
assert.Equal(t, "remove", cmd.Use)
|
||||||
t.Errorf("expected command name 'remove', got %q", cmd.Use)
|
assert.Equal(t, "Remove installed skill", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Remove installed skill" {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Len(t, cmd.Aliases, 2)
|
||||||
t.Error("expected command to have no subcommands")
|
assert.True(t, cmd.HasAlias("rm"))
|
||||||
}
|
assert.True(t, cmd.HasAlias("uninstall"))
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) != 2 {
|
|
||||||
t.Errorf("expected command to have 2 aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("rm") {
|
|
||||||
t.Errorf("expected command to have alias 'rm'")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("uninstall") {
|
|
||||||
t.Errorf("expected command to have alias 'uninstall'")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,24 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewSearchSubcommand(t *testing.T) {
|
func TestNewSearchSubcommand(t *testing.T) {
|
||||||
cmd := newSearchCommand(nil)
|
cmd := newSearchCommand(nil)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "search" {
|
assert.Equal(t, "search", cmd.Use)
|
||||||
t.Errorf("expected command name 'search', got %q", cmd.Use)
|
assert.Equal(t, "Search available skills", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Search available skills" {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.False(t, cmd.HasSubCommands())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasFlags())
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,26 @@
|
||||||
package skills
|
package skills
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewShowSubcommand(t *testing.T) {
|
func TestNewShowSubcommand(t *testing.T) {
|
||||||
cmd := newShowCommand(nil)
|
cmd := newShowCommand(nil)
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "show" {
|
assert.Equal(t, "show", cmd.Use)
|
||||||
t.Errorf("expected command name 'show', got %q", cmd.Use)
|
assert.Equal(t, "Show skill details", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Show skill details" {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.True(t, cmd.HasExample())
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.False(t, cmd.HasSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasExample() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have example")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.Len(t, cmd.Aliases, 0)
|
||||||
t.Error("expected command to have no subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
package skills
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestNewSkillsCommand(t *testing.T) {
|
|
||||||
cmd := NewSkillsCommand()
|
|
||||||
|
|
||||||
if cmd == nil {
|
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "skills" {
|
|
||||||
t.Errorf("expected command name 'skills', got %q", cmd.Use)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Manage skills" {
|
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) > 0 {
|
|
||||||
t.Errorf("expected command to have no aliases, got %d", len(cmd.Aliases))
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
|
||||||
t.Error("expected command to have nil Run()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE == nil {
|
|
||||||
t.Error("expected command to have non-nil RunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRunE == nil {
|
|
||||||
t.Error("expected command to have persistent pre-run hook")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +1,29 @@
|
||||||
package status
|
package status
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewStatusCommand(t *testing.T) {
|
func TestNewStatusCommand(t *testing.T) {
|
||||||
cmd := NewStatusCommand()
|
cmd := NewStatusCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "status" {
|
assert.Equal(t, "status", cmd.Use)
|
||||||
t.Errorf("expected command name 'status', got %q", cmd.Use)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) != 1 {
|
assert.Len(t, cmd.Aliases, 1)
|
||||||
t.Errorf("expected command to have 1 alias, got %d", len(cmd.Aliases))
|
assert.True(t, cmd.HasAlias("s"))
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("s") {
|
assert.Equal(t, "Show picoclaw status", cmd.Short)
|
||||||
t.Errorf("expected command to have alias 's'")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Show picoclaw status" {
|
assert.False(t, cmd.HasSubCommands())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Error("expected command to have no subcommands")
|
assert.Nil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE != nil {
|
|
||||||
t.Error("expected command to have nil RunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,31 @@
|
||||||
package version
|
package version
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNewVersionCommand(t *testing.T) {
|
func TestNewVersionCommand(t *testing.T) {
|
||||||
cmd := NewVersionCommand()
|
cmd := NewVersionCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "version" {
|
assert.Equal(t, "version", cmd.Use)
|
||||||
t.Errorf("expected command name 'version', got %q", cmd.Use)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Aliases) != 1 {
|
assert.Len(t, cmd.Aliases, 1)
|
||||||
t.Errorf("expected command to have 1 alias, got %d", len(cmd.Aliases))
|
assert.True(t, cmd.HasAlias("v"))
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAlias("v") {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Errorf("expected command to have alias 'v'")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
assert.Equal(t, "Show version information", cmd.Short)
|
||||||
t.Error("expected command to have no flags")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "Show version information" {
|
assert.False(t, cmd.HasSubCommands())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasSubCommands() {
|
assert.NotNil(t, cmd.Run)
|
||||||
t.Error("expected command to have no subcommands")
|
assert.Nil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run == nil {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Error("expected command to have non-nil Run()")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE != nil {
|
|
||||||
t.Error("expected command to have nil RunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,50 +2,29 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewPicoclawCommand(t *testing.T) {
|
func TestNewPicoclawCommand(t *testing.T) {
|
||||||
cmd := NewPicoclawCommand()
|
cmd := NewPicoclawCommand()
|
||||||
|
|
||||||
if cmd == nil {
|
require.NotNil(t, cmd)
|
||||||
t.Fatalf("expected non-nil command")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Use != "picoclaw" {
|
assert.Equal(t, "picoclaw", cmd.Use)
|
||||||
t.Errorf("expected command name 'picoclaw', got %q", cmd.Use)
|
assert.Equal(t, "picoclaw — Personal AI Assistant", cmd.Short)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Short != "picoclaw — Personal AI Assistant" {
|
assert.True(t, cmd.HasSubCommands())
|
||||||
t.Errorf("expected command short description, got %q", cmd.Short)
|
assert.True(t, cmd.HasAvailableSubCommands())
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasSubCommands() {
|
assert.False(t, cmd.HasFlags())
|
||||||
t.Error("expected command to have subcommands")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cmd.HasAvailableSubCommands() {
|
assert.Nil(t, cmd.Run)
|
||||||
t.Error("expected command to have available subcommands")
|
assert.Nil(t, cmd.RunE)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.HasFlags() {
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
t.Error("expected command to have no flags")
|
assert.Nil(t, cmd.PersistentPostRun)
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Run != nil {
|
|
||||||
t.Error("expected command to have nil Run()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.RunE != nil {
|
|
||||||
t.Error("expected command to have nil RunE()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPreRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPreRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.PersistentPostRun != nil {
|
|
||||||
t.Error("expected command to have nil PersistentPostRun()")
|
|
||||||
}
|
|
||||||
|
|
||||||
allowedCommands := map[string]struct{}{
|
allowedCommands := map[string]struct{}{
|
||||||
"agent": {},
|
"agent": {},
|
||||||
|
|
@ -59,13 +38,13 @@ func TestNewPicoclawCommand(t *testing.T) {
|
||||||
"version": {},
|
"version": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, subcmd := range cmd.Commands() {
|
subcommands := cmd.Commands()
|
||||||
if _, found := allowedCommands[subcmd.Name()]; !found {
|
assert.Len(t, subcommands, len(allowedCommands))
|
||||||
t.Errorf("unexpected subcommand %q", subcmd.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Hidden {
|
for _, subcmd := range subcommands {
|
||||||
t.Errorf("expected subcommand %q to be visible", subcmd.Name())
|
_, found := 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