- read netssh.yaml from the user config directory only, not from the working directory - refuse addresses from NetBox or the cache that are neither an IP address nor a hostname (ssh read "-oProxyCommand=…" as an option) - resolver chain stops at an API failure; only "no address" falls through to the next strategy - netssh --help and -h show netssh's help - start at most one background cache refresh per 5 minutes - validate the legacy netbox.url - page through all IP addresses of a host - CI: run format check, vet, and tests on pull requests and main - changelog for v0.0.25 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
30 lines
735 B
Go
30 lines
735 B
Go
package storage
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestWriteFileReplacesAtomically(t *testing.T) {
|
|
dir := filepath.Join(t.TempDir(), "new", "dir")
|
|
path := filepath.Join(dir, "file")
|
|
for _, content := range []string{"first", "second"} {
|
|
if err := WriteFile(path, []byte(content), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := os.ReadFile(path)
|
|
if err != nil || string(got) != content {
|
|
t.Fatalf("got %q, %v; want %q", got, err, content)
|
|
}
|
|
}
|
|
info, err := os.Stat(path)
|
|
if err != nil || info.Mode().Perm() != 0o600 {
|
|
t.Errorf("mode %v, %v; want 0600", info.Mode().Perm(), err)
|
|
}
|
|
entries, _ := os.ReadDir(dir)
|
|
if len(entries) != 1 {
|
|
t.Errorf("temporary files left behind: %v", entries)
|
|
}
|
|
}
|