mirror of
https://github.com/Gu1llaum-3/sshm.git
synced 2025-10-19 01:17:20 +02:00
- Fix history tests with proper test isolation using temp files - Fix CMD tests with proper string contains and simplified assertions - Add missing test utilities and helper functions - Improve test coverage across all packages - Remove flaky tests and replace with robust alternatives"
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func TestEditCommand(t *testing.T) {
|
|
// Test that the edit command is properly configured
|
|
if editCmd.Use != "edit <hostname>" {
|
|
t.Errorf("Expected Use 'edit <hostname>', got '%s'", editCmd.Use)
|
|
}
|
|
|
|
if editCmd.Short != "Edit an existing SSH host configuration" {
|
|
t.Errorf("Expected Short description, got '%s'", editCmd.Short)
|
|
}
|
|
|
|
// Test that it requires exactly 1 argument
|
|
err := editCmd.Args(editCmd, []string{})
|
|
if err == nil {
|
|
t.Error("Expected error for no arguments")
|
|
}
|
|
|
|
err = editCmd.Args(editCmd, []string{"host1", "host2"})
|
|
if err == nil {
|
|
t.Error("Expected error for too many arguments")
|
|
}
|
|
|
|
err = editCmd.Args(editCmd, []string{"hostname"})
|
|
if err != nil {
|
|
t.Errorf("Expected no error for 1 argument, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestEditCommandRegistration(t *testing.T) {
|
|
// Check that edit command is registered with root command
|
|
found := false
|
|
for _, cmd := range rootCmd.Commands() {
|
|
if cmd.Name() == "edit" {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Error("Edit command not found in root command")
|
|
}
|
|
}
|
|
|
|
func TestEditCommandHelp(t *testing.T) {
|
|
// Test help output
|
|
cmd := &cobra.Command{}
|
|
cmd.AddCommand(editCmd)
|
|
|
|
buf := new(bytes.Buffer)
|
|
cmd.SetOut(buf)
|
|
cmd.SetArgs([]string{"edit", "--help"})
|
|
|
|
// This should not return an error for help
|
|
err := cmd.Execute()
|
|
if err != nil {
|
|
t.Errorf("Expected no error for help command, got %v", err)
|
|
}
|
|
|
|
output := buf.String()
|
|
if !contains(output, "Edit an existing SSH host configuration") {
|
|
t.Error("Help output should contain command description")
|
|
}
|
|
} |