2f119478af
Funciones bash para instalar, conectar, desconectar, estado, IP, ciudades, países y protocolo. Funciones Go para gestionar contenedor NordVPN (run/start/stop) y parsear estado. Incluye tipo NordVPNStatus y tests para el parser. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package infra
|
|
|
|
import "testing"
|
|
|
|
func TestParseNordVPNStatus_Connected(t *testing.T) {
|
|
input := `Status: Connected
|
|
Hostname: es42.nordvpn.com
|
|
IP: 185.230.124.42
|
|
Country: Spain
|
|
City: Madrid
|
|
Current Technology: NordLynx
|
|
Current Protocol: nordlynx
|
|
Transfer: 1.2 MiB received, 500 KiB sent
|
|
Uptime: 5 minutes 32 seconds`
|
|
|
|
got := ParseNordVPNStatus(input)
|
|
|
|
if !got.Connected {
|
|
t.Error("expected Connected=true")
|
|
}
|
|
if got.Hostname != "es42.nordvpn.com" {
|
|
t.Errorf("Hostname = %q, want es42.nordvpn.com", got.Hostname)
|
|
}
|
|
if got.IP != "185.230.124.42" {
|
|
t.Errorf("IP = %q, want 185.230.124.42", got.IP)
|
|
}
|
|
if got.Country != "Spain" {
|
|
t.Errorf("Country = %q, want Spain", got.Country)
|
|
}
|
|
if got.City != "Madrid" {
|
|
t.Errorf("City = %q, want Madrid", got.City)
|
|
}
|
|
if got.Technology != "NordLynx" {
|
|
t.Errorf("Technology = %q, want NordLynx", got.Technology)
|
|
}
|
|
}
|
|
|
|
func TestParseNordVPNStatus_Disconnected(t *testing.T) {
|
|
input := `Status: Disconnected`
|
|
|
|
got := ParseNordVPNStatus(input)
|
|
|
|
if got.Connected {
|
|
t.Error("expected Connected=false")
|
|
}
|
|
if got.Status != "Disconnected" {
|
|
t.Errorf("Status = %q, want Disconnected", got.Status)
|
|
}
|
|
}
|
|
|
|
func TestParseNordVPNStatus_WithANSI(t *testing.T) {
|
|
input := "\x1b[32mStatus: Connected\x1b[0m\n\x1b[32m- Hostname: us1234.nordvpn.com\x1b[0m"
|
|
|
|
got := ParseNordVPNStatus(input)
|
|
|
|
if !got.Connected {
|
|
t.Error("expected Connected=true with ANSI codes")
|
|
}
|
|
if got.Hostname != "us1234.nordvpn.com" {
|
|
t.Errorf("Hostname = %q, want us1234.nordvpn.com", got.Hostname)
|
|
}
|
|
}
|