feat: funciones SSH para infra — conn, check, exec, download, upload, tunnel
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>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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")
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user