Files
Reims-Go/internal/app/ssh_flow_test.go
T
NwflowerandClaude Opus 5.5 c639682a88 refactor: remove unused functions and keep the codebase free of them
Delete functions that no product code calls, and fold "simple plus
WithOptions" pairs into the one signature callers actually use. Rename
the live macOS lifecycle functions that were labelled Legacy.

The architecture tests now share one source loader and reject functions
without a product caller and catalog messages nobody reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 20:55:03 -07:00

54 lines
1.7 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 := sshHostAliasForDriver("", "macos-tahoe"); got != "reims-macos-tahoe" {
t.Fatalf("alias = %q", got)
}
if got := sshHostAliasForDriver("", "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", "127.0.0.1", 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", "127.0.0.1", 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)
}
}