test makefiles: fix crash if --min-file-size <= --max-file-size

This commit is contained in:
Nick Craig-Wood 2022-04-12 13:44:04 +01:00
parent 118e8e1470
commit f583b86334

View File

@ -88,7 +88,10 @@ var makefilesCmd = &cobra.Command{
totalBytes := int64(0) totalBytes := int64(0)
for i := 0; i < numberOfFiles; i++ { for i := 0; i < numberOfFiles; i++ {
dir := dirs[randSource.Intn(len(dirs))] dir := dirs[randSource.Intn(len(dirs))]
size := randSource.Int63n(int64(maxFileSize-minFileSize)) + int64(minFileSize) size := int64(minFileSize)
if maxFileSize > minFileSize {
size += randSource.Int63n(int64(maxFileSize - minFileSize))
}
writeFile(dir, fileName(), size) writeFile(dir, fileName(), size)
totalBytes += size totalBytes += size
} }
@ -149,6 +152,9 @@ func commonInit() {
default: default:
source = randSource source = randSource
} }
if minFileSize > maxFileSize {
maxFileSize = minFileSize
}
} }
type zeroReader struct{} type zeroReader struct{}