test(recover): rename snapshot entry helper to avoid clash with tree entry
- commit
- aeec46d3b4465e629f731b56575c4c827630e1a0
- author
- brice · · 2026-10-10 01:59 UTC
- parent
- ecf0370
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +9 -9
M recover_test.go +9 -9
| @@ -93,7 +93,7 @@ func snapshotBytes(t *testing.T, seq uint64, entries ...snapEntry) []byte { | |||
| 93 | 93 | return encodeSnapshot(t, seq, entries) | |
| 94 | 94 | } | |
| 95 | 95 | ||
| 96 | - | func entry(k, v string, ver uint64) snapEntry { return snapEntry{[]byte(k), []byte(v), ver} } | |
| 96 | + | func snapEnt(k, v string, ver uint64) snapEntry { return snapEntry{[]byte(k), []byte(v), ver} } | |
| 97 | 97 | ||
| 98 | 98 | func wantState(t *testing.T, s *state, m map[string]string) { | |
| 99 | 99 | t.Helper() | |
| @@ -373,11 +373,11 @@ func TestRecoverSeqGap(t *testing.T) { | |||
| 373 | 373 | put(fx, logName(4), logBytes(4, []op{putOp("a", "1")})) | |
| 374 | 374 | }, | |
| 375 | 375 | "log after snapshot has a gap": func(fx *faultfs.FS) { | |
| 376 | - | put(fx, snapshotName(3), snapshotBytes(t, 3, entry("a", "1", 3))) | |
| 376 | + | put(fx, snapshotName(3), snapshotBytes(t, 3, snapEnt("a", "1", 3))) | |
| 377 | 377 | put(fx, logName(5), logBytes(5, []op{putOp("b", "2")})) | |
| 378 | 378 | }, | |
| 379 | 379 | "logs end before snapshot": func(fx *faultfs.FS) { | |
| 380 | - | put(fx, snapshotName(5), snapshotBytes(t, 5, entry("a", "1", 3))) | |
| 380 | + | put(fx, snapshotName(5), snapshotBytes(t, 5, snapEnt("a", "1", 3))) | |
| 381 | 381 | put(fx, logName(0), logBytes(0, []op{putOp("a", "1")})) | |
| 382 | 382 | }, | |
| 383 | 383 | "duplicate seq": func(fx *faultfs.FS) { | |
| @@ -400,7 +400,7 @@ func TestRecoverSeqGap(t *testing.T) { | |||
| 400 | 400 | ||
| 401 | 401 | func TestRecoverSnapshotThenLogs(t *testing.T) { | |
| 402 | 402 | fx := faultfs.New() | |
| 403 | - | put(fx, snapshotName(3), snapshotBytes(t, 3, entry("a", "1", 1), entry("b", "2", 3))) | |
| 403 | + | put(fx, snapshotName(3), snapshotBytes(t, 3, snapEnt("a", "1", 1), snapEnt("b", "2", 3))) | |
| 404 | 404 | // log-0 still holds records already in the snapshot; log-3 continues it. | |
| 405 | 405 | put(fx, logName(0), logBytes(0, []op{putOp("a", "old")}, []op{putOp("x", "gone")}, []op{putOp("b", "2")})) | |
| 406 | 406 | put(fx, logName(3), logBytes(3, []op{putOp("c", "3")}, []op{delOp("a")})) | |
| @@ -419,7 +419,7 @@ func TestRecoverSnapshotThenLogs(t *testing.T) { | |||
| 419 | 419 | ||
| 420 | 420 | func TestRecoverSnapshotWithoutLogCreatesLog(t *testing.T) { | |
| 421 | 421 | fx := faultfs.New() | |
| 422 | - | put(fx, snapshotName(7), snapshotBytes(t, 7, entry("a", "1", 7))) | |
| 422 | + | put(fx, snapshotName(7), snapshotBytes(t, 7, snapEnt("a", "1", 7))) | |
| 423 | 423 | s, rec := mustRecover(t, fx) | |
| 424 | 424 | wantState(t, s, map[string]string{"a": "1"}) | |
| 425 | 425 | if rec.snapSeq != 7 || rec.lastSeq != 7 || rec.logBase != 7 || rec.logSize != logHeaderSize { | |
| @@ -431,12 +431,12 @@ func TestRecoverSnapshotWithoutLogCreatesLog(t *testing.T) { | |||
| 431 | 431 | } | |
| 432 | 432 | ||
| 433 | 433 | func TestRecoverInvalidNewestSnapshotFallsBack(t *testing.T) { | |
| 434 | - | good := snapshotBytes(t, 2, entry("a", "1", 1), entry("b", "2", 2)) | |
| 435 | - | newer := snapshotBytes(t, 4, entry("a", "1", 1), entry("z", "9", 4)) | |
| 434 | + | good := snapshotBytes(t, 2, snapEnt("a", "1", 1), snapEnt("b", "2", 2)) | |
| 435 | + | newer := snapshotBytes(t, 4, snapEnt("a", "1", 1), snapEnt("z", "9", 4)) | |
| 436 | 436 | truncated := newer[:len(newer)-2] | |
| 437 | 437 | flipped := append([]byte(nil), newer...) | |
| 438 | 438 | flipped[30] ^= 1 | |
| 439 | - | wrongName := snapshotBytes(t, 3, entry("a", "1", 1)) | |
| 439 | + | wrongName := snapshotBytes(t, 3, snapEnt("a", "1", 1)) | |
| 440 | 440 | for name, bad := range map[string][]byte{"truncated": truncated, "flipped": flipped, "empty": nil, "seq/name mismatch": wrongName} { | |
| 441 | 441 | t.Run(name, func(t *testing.T) { | |
| 442 | 442 | fx := faultfs.New() | |
| @@ -486,7 +486,7 @@ func TestRecoverNoSnapshotStartsAtZero(t *testing.T) { | |||
| 486 | 486 | ||
| 487 | 487 | func TestRecoverSnapshotLoadOrderAndOwnership(t *testing.T) { | |
| 488 | 488 | fx := faultfs.New() | |
| 489 | - | put(fx, snapshotName(1), snapshotBytes(t, 1, entry("a", "1", 1), entry("b", "2", 1), entry("c", "3", 1))) | |
| 489 | + | put(fx, snapshotName(1), snapshotBytes(t, 1, snapEnt("a", "1", 1), snapEnt("b", "2", 1), snapEnt("c", "3", 1))) | |
| 490 | 490 | var keys []string | |
| 491 | 491 | var held [][]byte | |
| 492 | 492 | _, err := recoverDir(fx, testDir, nil, func(k, v []byte, ver uint64) { | |
| @@ -93,7 +93,7 @@ func snapshotBytes(t *testing.T, seq uint64, entries ...snapEntry) []byte { | |||||
| 93 | return encodeSnapshot(t, seq, entries) | 93 | return encodeSnapshot(t, seq, entries) | ||
| 94 | } | 94 | } | ||
| 95 | 95 | ||||
| 96 | - | func entry(k, v string, ver uint64) snapEntry { return snapEntry{[]byte(k), []byte(v), ver} } | 96 | + | func snapEnt(k, v string, ver uint64) snapEntry { return snapEntry{[]byte(k), []byte(v), ver} } |
| 97 | 97 | ||||
| 98 | func wantState(t *testing.T, s *state, m map[string]string) { | 98 | func wantState(t *testing.T, s *state, m map[string]string) { | ||
| 99 | t.Helper() | 99 | t.Helper() | ||
| @@ -373,11 +373,11 @@ func TestRecoverSeqGap(t *testing.T) { | |||||
| 373 | put(fx, logName(4), logBytes(4, []op{putOp("a", "1")})) | 373 | put(fx, logName(4), logBytes(4, []op{putOp("a", "1")})) | ||
| 374 | }, | 374 | }, | ||
| 375 | "log after snapshot has a gap": func(fx *faultfs.FS) { | 375 | "log after snapshot has a gap": func(fx *faultfs.FS) { | ||
| 376 | - | put(fx, snapshotName(3), snapshotBytes(t, 3, entry("a", "1", 3))) | 376 | + | put(fx, snapshotName(3), snapshotBytes(t, 3, snapEnt("a", "1", 3))) |
| 377 | put(fx, logName(5), logBytes(5, []op{putOp("b", "2")})) | 377 | put(fx, logName(5), logBytes(5, []op{putOp("b", "2")})) | ||
| 378 | }, | 378 | }, | ||
| 379 | "logs end before snapshot": func(fx *faultfs.FS) { | 379 | "logs end before snapshot": func(fx *faultfs.FS) { | ||
| 380 | - | put(fx, snapshotName(5), snapshotBytes(t, 5, entry("a", "1", 3))) | 380 | + | put(fx, snapshotName(5), snapshotBytes(t, 5, snapEnt("a", "1", 3))) |
| 381 | put(fx, logName(0), logBytes(0, []op{putOp("a", "1")})) | 381 | put(fx, logName(0), logBytes(0, []op{putOp("a", "1")})) | ||
| 382 | }, | 382 | }, | ||
| 383 | "duplicate seq": func(fx *faultfs.FS) { | 383 | "duplicate seq": func(fx *faultfs.FS) { | ||
| @@ -400,7 +400,7 @@ func TestRecoverSeqGap(t *testing.T) { | |||||
| 400 | 400 | ||||
| 401 | func TestRecoverSnapshotThenLogs(t *testing.T) { | 401 | func TestRecoverSnapshotThenLogs(t *testing.T) { | ||
| 402 | fx := faultfs.New() | 402 | fx := faultfs.New() | ||
| 403 | - | put(fx, snapshotName(3), snapshotBytes(t, 3, entry("a", "1", 1), entry("b", "2", 3))) | 403 | + | put(fx, snapshotName(3), snapshotBytes(t, 3, snapEnt("a", "1", 1), snapEnt("b", "2", 3))) |
| 404 | // log-0 still holds records already in the snapshot; log-3 continues it. | 404 | // log-0 still holds records already in the snapshot; log-3 continues it. | ||
| 405 | put(fx, logName(0), logBytes(0, []op{putOp("a", "old")}, []op{putOp("x", "gone")}, []op{putOp("b", "2")})) | 405 | put(fx, logName(0), logBytes(0, []op{putOp("a", "old")}, []op{putOp("x", "gone")}, []op{putOp("b", "2")})) | ||
| 406 | put(fx, logName(3), logBytes(3, []op{putOp("c", "3")}, []op{delOp("a")})) | 406 | put(fx, logName(3), logBytes(3, []op{putOp("c", "3")}, []op{delOp("a")})) | ||
| @@ -419,7 +419,7 @@ func TestRecoverSnapshotThenLogs(t *testing.T) { | |||||
| 419 | 419 | ||||
| 420 | func TestRecoverSnapshotWithoutLogCreatesLog(t *testing.T) { | 420 | func TestRecoverSnapshotWithoutLogCreatesLog(t *testing.T) { | ||
| 421 | fx := faultfs.New() | 421 | fx := faultfs.New() | ||
| 422 | - | put(fx, snapshotName(7), snapshotBytes(t, 7, entry("a", "1", 7))) | 422 | + | put(fx, snapshotName(7), snapshotBytes(t, 7, snapEnt("a", "1", 7))) |
| 423 | s, rec := mustRecover(t, fx) | 423 | s, rec := mustRecover(t, fx) | ||
| 424 | wantState(t, s, map[string]string{"a": "1"}) | 424 | wantState(t, s, map[string]string{"a": "1"}) | ||
| 425 | if rec.snapSeq != 7 || rec.lastSeq != 7 || rec.logBase != 7 || rec.logSize != logHeaderSize { | 425 | if rec.snapSeq != 7 || rec.lastSeq != 7 || rec.logBase != 7 || rec.logSize != logHeaderSize { | ||
| @@ -431,12 +431,12 @@ func TestRecoverSnapshotWithoutLogCreatesLog(t *testing.T) { | |||||
| 431 | } | 431 | } | ||
| 432 | 432 | ||||
| 433 | func TestRecoverInvalidNewestSnapshotFallsBack(t *testing.T) { | 433 | func TestRecoverInvalidNewestSnapshotFallsBack(t *testing.T) { | ||
| 434 | - | good := snapshotBytes(t, 2, entry("a", "1", 1), entry("b", "2", 2)) | 434 | + | good := snapshotBytes(t, 2, snapEnt("a", "1", 1), snapEnt("b", "2", 2)) |
| 435 | - | newer := snapshotBytes(t, 4, entry("a", "1", 1), entry("z", "9", 4)) | 435 | + | newer := snapshotBytes(t, 4, snapEnt("a", "1", 1), snapEnt("z", "9", 4)) |
| 436 | truncated := newer[:len(newer)-2] | 436 | truncated := newer[:len(newer)-2] | ||
| 437 | flipped := append([]byte(nil), newer...) | 437 | flipped := append([]byte(nil), newer...) | ||
| 438 | flipped[30] ^= 1 | 438 | flipped[30] ^= 1 | ||
| 439 | - | wrongName := snapshotBytes(t, 3, entry("a", "1", 1)) | 439 | + | wrongName := snapshotBytes(t, 3, snapEnt("a", "1", 1)) |
| 440 | for name, bad := range map[string][]byte{"truncated": truncated, "flipped": flipped, "empty": nil, "seq/name mismatch": wrongName} { | 440 | for name, bad := range map[string][]byte{"truncated": truncated, "flipped": flipped, "empty": nil, "seq/name mismatch": wrongName} { | ||
| 441 | t.Run(name, func(t *testing.T) { | 441 | t.Run(name, func(t *testing.T) { | ||
| 442 | fx := faultfs.New() | 442 | fx := faultfs.New() | ||
| @@ -486,7 +486,7 @@ func TestRecoverNoSnapshotStartsAtZero(t *testing.T) { | |||||
| 486 | 486 | ||||
| 487 | func TestRecoverSnapshotLoadOrderAndOwnership(t *testing.T) { | 487 | func TestRecoverSnapshotLoadOrderAndOwnership(t *testing.T) { | ||
| 488 | fx := faultfs.New() | 488 | fx := faultfs.New() | ||
| 489 | - | put(fx, snapshotName(1), snapshotBytes(t, 1, entry("a", "1", 1), entry("b", "2", 1), entry("c", "3", 1))) | 489 | + | put(fx, snapshotName(1), snapshotBytes(t, 1, snapEnt("a", "1", 1), snapEnt("b", "2", 1), snapEnt("c", "3", 1))) |
| 490 | var keys []string | 490 | var keys []string | ||
| 491 | var held [][]byte | 491 | var held [][]byte | ||
| 492 | _, err := recoverDir(fx, testDir, nil, func(k, v []byte, ver uint64) { | 492 | _, err := recoverDir(fx, testDir, nil, func(k, v []byte, ver uint64) { | ||