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