2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-16 10:05:25 +00:00
restic/internal/fs/preallocate_test.go

39 lines
791 B
Go
Raw Normal View History

2021-02-02 14:43:40 +00:00
package fs
2020-08-19 20:31:10 +00:00
import (
"os"
"path"
"strconv"
"syscall"
2020-08-19 20:31:10 +00:00
"testing"
"github.com/restic/restic/internal/test"
)
func TestPreallocate(t *testing.T) {
for _, i := range []int64{0, 1, 4096, 1024 * 1024} {
t.Run(strconv.FormatInt(i, 10), func(t *testing.T) {
dirpath := test.TempDir(t)
2020-08-19 20:31:10 +00:00
flags := os.O_CREATE | os.O_TRUNC | os.O_WRONLY
wr, err := os.OpenFile(path.Join(dirpath, "test"), flags, 0600)
test.OK(t, err)
2021-01-30 18:35:46 +00:00
defer func() {
test.OK(t, wr.Close())
}()
2020-08-19 20:31:10 +00:00
2021-02-02 14:43:40 +00:00
err = PreallocateFile(wr, i)
if err == syscall.ENOTSUP {
t.SkipNow()
}
2020-08-19 20:31:10 +00:00
test.OK(t, err)
fi, err := wr.Stat()
test.OK(t, err)
2021-02-02 14:43:40 +00:00
efi := ExtendedStat(fi)
2020-08-19 20:31:10 +00:00
test.Assert(t, efi.Size == i || efi.Blocks > 0, "Preallocated size of %v, got size %v block %v", i, efi.Size, efi.Blocks)
})
}
}