Resolve host aliases through ~/.ssh/config with kevinburke/ssh_config: HostName defaults to the alias, key=value syntax, Host * defaults, Include, quotes, several IdentityFile, '#' inside values (N-P1-5). Endpoint.Key includes the user (N-P2-3). Port the hosts.dat store with atomic writes and a base64 password field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
769 B
Go
31 lines
769 B
Go
package atomicwrite
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestWriteFileReplacesAndCleansUp(t *testing.T) {
|
|
dir := t.TempDir()
|
|
p := filepath.Join(dir, "f")
|
|
if err := os.WriteFile(p, []byte("old content"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := WriteFile(p, []byte("new"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(p)
|
|
if err != nil || string(b) != "new" {
|
|
t.Fatalf("content = %q, %v", b, err)
|
|
}
|
|
if fi, _ := os.Stat(p); fi.Mode().Perm() != 0o600 {
|
|
t.Errorf("mode = %v", fi.Mode().Perm())
|
|
}
|
|
if ents, _ := os.ReadDir(dir); len(ents) != 1 {
|
|
t.Errorf("temp files left: %v", ents)
|
|
}
|
|
if err := WriteFile(filepath.Join(dir, "missing", "f"), nil, 0o600); err == nil {
|
|
t.Error("want error for missing directory")
|
|
}
|
|
}
|