Files
seaweedfs/weed/command/compact_test.go
T
Chris LuandClaude Opus 5.5 c57f58959d compact: remove the partial .cpd/.cpx when compaction fails
A failed weed compact exited through glog.Fatalf and left a partial .cpd
next to the volume. Remove both outputs and report the failure in the
exit status instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 05:02:40 -08:00

32 lines
1.0 KiB
Go

package command
import (
"bytes"
"os"
"testing"
)
func TestCompactDataMethodBadHeaderLeavesNoOutput(t *testing.T) {
dir := t.TempDir()
base, offsets := writeFixTestVolume(t, dir, 5)
doFixOneVolume(dir, "fix_7", "fix", 7, true)
overwriteAt(t, base+".dat", offsets[2], bytes.Repeat([]byte{0xa5}, 16))
savedDir, savedCollection, savedId, savedMethod, savedStatus := *compactVolumePath, *compactVolumeCollection, *compactVolumeId, *compactMethod, commandExitStatus
defer func() {
*compactVolumePath, *compactVolumeCollection, *compactVolumeId, *compactMethod, commandExitStatus = savedDir, savedCollection, savedId, savedMethod, savedStatus
}()
*compactVolumePath, *compactVolumeCollection, *compactVolumeId, *compactMethod, commandExitStatus = dir, "fix", 7, "data", 0
runCompact(cmdCompact, nil)
if CommandExitStatus() == 0 {
t.Error("expected a non-zero exit status")
}
for _, ext := range []string{".cpd", ".cpx"} {
if _, err := os.Stat(base + ext); !os.IsNotExist(err) {
t.Errorf("%s left behind: %v", ext, err)
}
}
}