summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2022-01-04 15:21:20 +0100
committerJakob Unterwurzacher2022-01-04 15:21:20 +0100
commit700ae685cc7cb99b396caeaeee4e39eeac20f1c7 (patch)
tree760586f04bb0ab513a21c2dd45fb6eccd1aa410e
parent4b251f3ce1f0a0472ed10a00aeef70c69ba03a5d (diff)
tests: improve SEEK_DATA test for MacOS
(1) Create a 1 GiB file instead of 1 TiB, because apparently, on MacOS, the file (sometimes?) is not created sparse, and fills up users' disks: https://github.com/rfjakob/gocryptfs/issues/625 (2) On darwin, SEEK_DATA is not the same as on Linux ( https://github.com/golang/go/commit/2f8b555de27198775f9606e001ef19b76efdb415 ) so use the value provided by the unix package.
-rw-r--r--tests/defaults/main_test.go16
-rw-r--r--tests/reverse/correctness_test.go14
2 files changed, 14 insertions, 16 deletions
diff --git a/tests/defaults/main_test.go b/tests/defaults/main_test.go
index 43019ba..0f31a72 100644
--- a/tests/defaults/main_test.go
+++ b/tests/defaults/main_test.go
@@ -14,6 +14,8 @@ import (
"syscall"
"testing"
+ "golang.org/x/sys/unix"
+
"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
)
@@ -267,15 +269,15 @@ func TestCpWarnings(t *testing.T) {
}
}
-// TestSeekData tests that fs.FileLseeker is implemented
+// TestSeekData tests that SEEK_DATA works
func TestSeekData(t *testing.T) {
fn := filepath.Join(test_helpers.DefaultPlainDir, t.Name())
f, err := os.Create(fn)
if err != nil {
t.Fatal(err)
}
- var oneTiB int64 = 1024 * 1024 * 1024 * 1024
- if _, err = f.Seek(oneTiB, 0); err != nil {
+ var dataOffset int64 = 1024 * 1024 * 1024 // 1 GiB
+ if _, err = f.Seek(dataOffset, 0); err != nil {
t.Fatal(err)
}
if _, err = f.Write([]byte("foo")); err != nil {
@@ -283,18 +285,16 @@ func TestSeekData(t *testing.T) {
}
f.Close()
- const SEEK_DATA = 3
-
f, err = os.Open(fn)
if err != nil {
t.Fatal(err)
}
- off, err := f.Seek(1024*1024, SEEK_DATA)
+ off, err := f.Seek(1024*1024, unix.SEEK_DATA)
if err != nil {
t.Fatal(err)
}
- if off < oneTiB-1024*1024 {
- t.Errorf("off=%d, expected=%d\n", off, oneTiB)
+ if off < dataOffset-1024*1024 {
+ t.Errorf("off=%d, expected=%d\n", off, dataOffset)
}
f.Close()
}
diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go
index 090a468..4a5224c 100644
--- a/tests/reverse/correctness_test.go
+++ b/tests/reverse/correctness_test.go
@@ -259,7 +259,7 @@ func TestStatfs(t *testing.T) {
}
}
-// TestSeekData tests that fs.FileLseeker is implemented
+// TestSeekData tests that SEEK_DATA works
func TestSeekData(t *testing.T) {
if !plaintextnames {
t.Skip()
@@ -270,8 +270,8 @@ func TestSeekData(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- var oneTiB int64 = 1024 * 1024 * 1024 * 1024
- if _, err = f.Seek(oneTiB, 0); err != nil {
+ var dataOffset int64 = 1 * 1024 * 1024 * 1024 // 1 GiB
+ if _, err = f.Seek(dataOffset, 0); err != nil {
t.Fatal(err)
}
if _, err = f.Write([]byte("foo")); err != nil {
@@ -279,19 +279,17 @@ func TestSeekData(t *testing.T) {
}
f.Close()
- const SEEK_DATA = 3
-
fn2 := filepath.Join(dirB, t.Name())
f, err = os.Open(fn2)
if err != nil {
t.Fatal(err)
}
- off, err := f.Seek(1024*1024, SEEK_DATA)
+ off, err := f.Seek(1024*1024, unix.SEEK_DATA)
if err != nil {
t.Fatal(err)
}
- if off < oneTiB-1024*1024 {
- t.Errorf("off=%d, expected=%d\n", off, oneTiB)
+ if off < dataOffset-1024*1024 {
+ t.Errorf("off=%d, expected=%d\n", off, dataOffset)
}
f.Close()
}