style: add blank lines between declarations and statement blocks

Separate top-level declarations and multi-line statements with blank
lines, keeping an "if err != nil" check next to the statement it
belongs to. Expand semicolon one-liners, group the nativeTransport
fields by purpose, and format the cgo preamble as readable C.
Apart from the expanded one-liners and the C preamble, the change
is whitespace only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 18:36:19 +01:00
1 parent ec0297fd23
commit a6fda8f8d3
25 files changed
+929 -41

No files matched your search

+13
View File
@@ -12,6 +12,7 @@ func testConfig() Config {
return Config{Source: Endpoint{Config: "/clusters/a/ceph.conf", Keyring: "/clusters/a/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "source", Mount: "/mnt/a"},
Target: Endpoint{Config: "/clusters/b/ceph.conf", Keyring: "/clusters/b/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "target", Mount: "/mnt/b"}}
}
func TestConfigRejectsUnsafePathsAndNames(t *testing.T) {
for name, modify := range map[string]func(*Config){
"overlap": func(c *Config) { c.Target.Mount = "/mnt/a/nested" },
@@ -33,6 +34,7 @@ func TestConfigRejectsUnsafePathsAndNames(t *testing.T) {
}
})
}
if err := testConfig().Validate(); err != nil {
t.Fatal(err)
}
@@ -45,16 +47,19 @@ func TestNativeConfigAndResumeSettings(t *testing.T) {
if err := c.Validate(); err != nil {
t.Fatal(err)
}
changed := c
changed.Workers, changed.BandwidthKiB = 32, 100000
if !sameMigrationIdentity(c, changed) {
t.Fatal("runtime settings invalidated resume identity")
}
changed.Target.Subvolume = "another"
if sameMigrationIdentity(c, changed) {
t.Fatal("accepted a different target")
}
}
func TestStrictJSONConfig(t *testing.T) {
b, _ := json.Marshal(testConfig())
for name, data := range map[string]string{"unknown": strings.TrimSuffix(string(b), "}") + ", \"typo\": true}", "trailing": string(b) + " {}", "truncated": string(b[:len(b)-2])} {
@@ -63,37 +68,45 @@ func TestStrictJSONConfig(t *testing.T) {
if err := os.WriteFile(p, []byte(data), 0600); err != nil {
t.Fatal(err)
}
if _, err := ReadConfig(p); err == nil {
t.Fatal("accepted invalid JSON config")
}
})
}
}
func TestDataPathRejectsEscapeAndSymlink(t *testing.T) {
root := t.TempDir()
if err := os.Mkdir(filepath.Join(root, "real"), 0700); err != nil {
t.Fatal(err)
}
if err := os.Symlink(t.TempDir(), filepath.Join(root, "link")); err != nil {
t.Fatal(err)
}
for _, path := range []string{"/../escape", "/real/../real", "relative", "/link", "/"} {
if _, err := dataPath(root, path); err == nil {
t.Fatalf("accepted %q", path)
}
}
if got, err := dataPath(root, "/real"); err != nil || got != filepath.Join(root, "real") {
t.Fatalf("got %q, %v", got, err)
}
}
func TestPrivateDirectoriesNeverFollowsSymlink(t *testing.T) {
root, outside := t.TempDir(), t.TempDir()
if err := os.Symlink(outside, filepath.Join(root, "link")); err != nil {
t.Fatal(err)
}
if err := privateDirectories(filepath.Join(root, "link", "new")); err == nil {
t.Fatal("followed symlink")
}
if _, err := os.Stat(filepath.Join(outside, "new")); !os.IsNotExist(err) {
t.Fatal("created directory through symlink")
}