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:
1 parent
ec0297fd23
commit
a6fda8f8d3
25 files changed
+929
-41
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
func testState() *State {
|
||||
return &State{Version: stateVersion, ID: "1234567890abcdef1234567890abcdef", Config: testConfig(), Phase: "syncing"}
|
||||
}
|
||||
|
||||
func TestStateAtomicAndPrivate(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "state.json")
|
||||
s := testState()
|
||||
@@ -18,10 +19,12 @@ func TestStateAtomicAndPrivate(t *testing.T) {
|
||||
if err := SaveState(p, s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
st, err := os.Stat(p)
|
||||
if err != nil || st.Mode().Perm() != 0600 {
|
||||
t.Fatalf("state permissions: %v, %v", st, err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
@@ -33,20 +36,25 @@ func TestStateAtomicAndPrivate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
got, err := LoadState(p)
|
||||
if err != nil {
|
||||
t.Fatalf("reader observed partial state: %v", err)
|
||||
}
|
||||
|
||||
if got.ID != s.ID {
|
||||
t.Fatal("state identity changed")
|
||||
}
|
||||
|
||||
if len(got.Notes) != 1 || got.Notes[0] != SnapshotIdentityNote {
|
||||
t.Fatal("snapshot identity note was lost")
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestStateRejectsCorruption(t *testing.T) {
|
||||
for name, modify := range map[string]func(*State){
|
||||
"version": func(s *State) { s.Version++ },
|
||||
@@ -68,37 +76,45 @@ func TestStateRejectsCorruption(t *testing.T) {
|
||||
if err := SaveState(p, s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := LoadState(p); err == nil {
|
||||
t.Fatal("accepted corrupt state")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
p := filepath.Join(t.TempDir(), "state.json")
|
||||
b, _ := json.Marshal(testState())
|
||||
if err := os.WriteFile(p, append(b, []byte(" {}")...), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := LoadState(p); err == nil {
|
||||
t.Fatal("accepted trailing data")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockExclusionAndRelease(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "lock")
|
||||
first, err := lockFile(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if second, err := lockFile(p); err == nil {
|
||||
second.Close()
|
||||
t.Fatal("second process acquired lock")
|
||||
}
|
||||
|
||||
first.Close()
|
||||
third, err := lockFile(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
third.Close()
|
||||
}
|
||||
|
||||
func TestTargetClaimExcludesOtherJobsAndSurvivesStateLoss(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
c := testConfig()
|
||||
@@ -106,34 +122,42 @@ func TestTargetClaimExcludesOtherJobsAndSurvivesStateLoss(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if second, err := claimTarget(root, "fsid", c.Target, "job-one"); err == nil {
|
||||
second.Close()
|
||||
t.Fatal("concurrent use allowed")
|
||||
}
|
||||
|
||||
first.Close()
|
||||
if other, err := claimTarget(root, "fsid", c.Target, "job-two"); err == nil {
|
||||
other.Close()
|
||||
t.Fatal("different job stole target")
|
||||
}
|
||||
|
||||
resumed, err := claimTarget(root, "fsid", c.Target, "job-one")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
resumed.Close()
|
||||
}
|
||||
|
||||
func TestStateAndLockRejectSymlinks(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
real := filepath.Join(root, "real")
|
||||
if err := SaveState(real, testState()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
link := filepath.Join(root, "link")
|
||||
if err := os.Symlink(real, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := LoadState(link); err == nil {
|
||||
t.Fatal("followed state symlink")
|
||||
}
|
||||
|
||||
if f, err := lockFile(link); err == nil {
|
||||
f.Close()
|
||||
t.Fatal("followed lock symlink")
|
||||
|
||||
Reference in new issue
Block a user