Resolve stats, thumbnails, window actions, SSH, affinity and diagnostic bundles through VMRef-aware VM information. Isolate caches, SSH aliases and frontend pollers for same-name VMs while preserving macOS defaults.
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSSHHostAlias(t *testing.T) {
|
|
if sshHostAliasForDriver("test.driver.linux", "dev") == sshHostAliasForDriver("", "dev") {
|
|
t.Fatal("same-name drivers share an SSH alias")
|
|
}
|
|
if got := sshHostAlias("macos-tahoe"); got != "reims-macos-tahoe" {
|
|
t.Fatalf("alias = %q", got)
|
|
}
|
|
if got := sshHostAlias("My Mac 26"); got != "reims-my-mac-26" {
|
|
t.Fatalf("alias = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestUpsertSSHConfigBlockIdempotent(t *testing.T) {
|
|
cfg := filepath.Join(t.TempDir(), "config")
|
|
initial := "Host prod\n HostName 10.0.0.5\n"
|
|
if err := os.WriteFile(cfg, []byte(initial), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := upsertSSHConfigBlock(cfg, "macos-tahoe", "reims-macos-tahoe", 2222, "alice"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b1, _ := os.ReadFile(cfg)
|
|
s1 := string(b1)
|
|
if !strings.Contains(s1, "Host prod") || !strings.Contains(s1, "Host reims-macos-tahoe") || !strings.Contains(s1, "Port 2222") || !strings.Contains(s1, "User alice") {
|
|
t.Fatalf("unexpected first config:\n%s", s1)
|
|
}
|
|
|
|
// Updating port and user must replace the block in place without duplicating it.
|
|
if err := upsertSSHConfigBlock(cfg, "macos-tahoe", "reims-macos-tahoe", 2223, "bob"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b2, _ := os.ReadFile(cfg)
|
|
s2 := string(b2)
|
|
if strings.Count(s2, "Host reims-macos-tahoe") != 1 {
|
|
t.Fatalf("expected single block, got:\n%s", s2)
|
|
}
|
|
if !strings.Contains(s2, "Port 2223") || !strings.Contains(s2, "User bob") || strings.Contains(s2, "User alice") {
|
|
t.Fatalf("block not updated:\n%s", s2)
|
|
}
|
|
if !strings.Contains(s2, "Host prod") {
|
|
t.Fatalf("existing user config lost:\n%s", s2)
|
|
}
|
|
}
|