refactor: move V1 code into v1/ subdirectory
- git mv cmd/ internal/ pkg/ test/ go.mod go.sum Makefile build.sh docs/ v1/ - Create v1/README.md with V1 documentation - Update root README for V1 + V2 structure - V1 still builds (cd v1 && go build ./cmd/hostkeeper) and 105 tests pass - Root is now clean for V2 development
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.tukangketik.id/swanadiva/hostkeeper/internal/models"
|
||||
)
|
||||
|
||||
func TestConnectCommandExists(t *testing.T) {
|
||||
if connectCmd == nil {
|
||||
t.Fatal("connectCmd should not be nil")
|
||||
}
|
||||
|
||||
if connectCmd.Use != "connect <host-name-or-id>" {
|
||||
t.Errorf("expected Use 'connect <host-name-or-id>', got '%s'", connectCmd.Use)
|
||||
}
|
||||
|
||||
if connectCmd.Short == "" {
|
||||
t.Error("Short description should not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnectCommandFlags(t *testing.T) {
|
||||
expectedFlags := []string{"timeout", "native"}
|
||||
for _, flagName := range expectedFlags {
|
||||
if connectCmd.Flags().Lookup(flagName) == nil {
|
||||
t.Errorf("flag '%s' should be defined", flagName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnectArgs(t *testing.T) {
|
||||
if connectCmd.Args == nil {
|
||||
t.Error("Args validator should not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildSSHArgs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
host *models.Host
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "default port 22",
|
||||
host: &models.Host{
|
||||
Name: "test",
|
||||
Hostname: "192.168.1.1",
|
||||
Port: 22,
|
||||
Username: "admin",
|
||||
},
|
||||
want: []string{"admin@192.168.1.1"},
|
||||
},
|
||||
{
|
||||
name: "non-default port 2222",
|
||||
host: &models.Host{
|
||||
Name: "test",
|
||||
Hostname: "192.168.1.1",
|
||||
Port: 2222,
|
||||
Username: "admin",
|
||||
},
|
||||
want: []string{"-p", "2222", "admin@192.168.1.1"},
|
||||
},
|
||||
{
|
||||
name: "key auth with KeyID",
|
||||
host: &models.Host{
|
||||
Name: "test",
|
||||
Hostname: "10.0.0.1",
|
||||
Port: 22,
|
||||
Username: "root",
|
||||
Auth: models.AuthConfig{
|
||||
Type: "key",
|
||||
KeyID: "~/.ssh/id_rsa",
|
||||
},
|
||||
},
|
||||
want: []string{"root@10.0.0.1"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := buildSSHArgs(tt.host)
|
||||
if len(got) != len(tt.want) {
|
||||
t.Errorf("buildSSHArgs() = %v, want %v", got, tt.want)
|
||||
return
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != tt.want[i] {
|
||||
t.Errorf("buildSSHArgs() = %v, want %v", got, tt.want)
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user