6d0d63cb23
Conjunto completo de funciones SSH para operaciones remotas: conexión, verificación de host, ejecución de comandos, transferencia de archivos (upload/download) y gestión de túneles. Incluye tipo SSHConn y tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
797 B
Go
41 lines
797 B
Go
package infra
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func sshTestConn() SSHConn {
|
|
return SSHConn{
|
|
Host: "organic-machine.com",
|
|
User: "ubuntu",
|
|
KeyPath: "/home/lucas/.ssh/organic-machine",
|
|
}
|
|
}
|
|
|
|
func skipIfNoSSH(t *testing.T) SSHConn {
|
|
t.Helper()
|
|
conn := sshTestConn()
|
|
if err := SSHCheck(conn); err != nil {
|
|
t.Skipf("SSH no disponible: %v", err)
|
|
}
|
|
return conn
|
|
}
|
|
|
|
func TestSSHCheck(t *testing.T) {
|
|
t.Run("conecta a organic-machine", func(t *testing.T) {
|
|
conn := sshTestConn()
|
|
err := SSHCheck(conn)
|
|
if err != nil {
|
|
t.Skipf("SSH no disponible: %v", err)
|
|
}
|
|
})
|
|
|
|
t.Run("falla con host inexistente", func(t *testing.T) {
|
|
conn := SSHConn{Host: "192.0.2.1", Port: 22, User: "nobody"}
|
|
err := SSHCheck(conn)
|
|
if err == nil {
|
|
t.Error("esperaba error con host inexistente")
|
|
}
|
|
})
|
|
}
|