summaryrefslogtreecommitdiff
path: root/internal/fs/preallocate_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fs/preallocate_test.go')
-rw-r--r--internal/fs/preallocate_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/fs/preallocate_test.go b/internal/fs/preallocate_test.go
new file mode 100644
index 000000000..9dabd2f36
--- /dev/null
+++ b/internal/fs/preallocate_test.go
@@ -0,0 +1,38 @@
+package fs
+
+import (
+ "os"
+ "path"
+ "strconv"
+ "syscall"
+ "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)
+
+ flags := os.O_CREATE | os.O_TRUNC | os.O_WRONLY
+ wr, err := os.OpenFile(path.Join(dirpath, "test"), flags, 0600)
+ test.OK(t, err)
+ defer func() {
+ test.OK(t, wr.Close())
+ }()
+
+ err = PreallocateFile(wr, i)
+ if err == syscall.ENOTSUP {
+ t.SkipNow()
+ }
+ test.OK(t, err)
+
+ fi, err := wr.Stat()
+ test.OK(t, err)
+
+ efi := ExtendedStat(fi)
+ test.Assert(t, efi.Size == i || efi.Blocks > 0, "Preallocated size of %v, got size %v block %v", i, efi.Size, efi.Blocks)
+ })
+ }
+}