Skip to content

Commit

Permalink
tests: reverse: TestMtimePlus10: fix darwin build
Browse files Browse the repository at this point in the history
Darwin does not have Stat_t.mtim:

+ go test -c -tags without_openssl -o /dev/null github.com/rfjakob/gocryptfs/v2/tests/reverse
Error: tests/reverse/correctness_test.go:407:15: name_stat.Mtim undefined (type syscall.Stat_t has no field or method Mtim)
Error: tests/reverse/correctness_test.go:407:37: long_stat.Mtim undefined (type syscall.Stat_t has no field or method Mtim)
Error: tests/reverse/correctness_test.go:410:15: name_stat.Ctim undefined (type syscall.Stat_t has no field or method Ctim)
Error: tests/reverse/correctness_test.go:410:37: long_stat.Ctim undefined (type syscall.Stat_t has no field or method Ctim)
Error: tests/reverse/correctness_test.go:424:16: diriv_stat.Mtim undefined (type syscall.Stat_t has no field or method Mtim)
Error: tests/reverse/correctness_test.go:424:42: workdirA_stat.Mtim undefined (type syscall.Stat_t has no field or method Mtim)
Error: tests/reverse/correctness_test.go:427:16: diriv_stat.Ctim undefined (type syscall.Stat_t has no field or method Ctim)
Error: tests/reverse/correctness_test.go:427:42: workdirA_stat.Ctim undefined (type syscall.Stat_t has no field or method Ctim)

Switch to os.Stat.
  • Loading branch information
rfjakob committed Jan 18, 2025
1 parent 38936cb commit a0105e6
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions tests/reverse/correctness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ func TestMtimePlus10(t *testing.T) {
if err := os.WriteFile(long, nil, 0600); err != nil {
t.Fatal(err)
}
var long_stat syscall.Stat_t
if err := syscall.Stat(long, &long_stat); err != nil {
long_stat, err := os.Stat(long)
if err != nil {
t.Fatal(err)
}

var workdirA_stat syscall.Stat_t
if err := syscall.Stat(workdirA, &workdirA_stat); err != nil {
workdirA_stat, err := os.Stat(workdirA)
if err != nil {
t.Fatal(err)
}

Expand All @@ -400,31 +400,24 @@ func TestMtimePlus10(t *testing.T) {
if len(matches) != 1 {
t.Fatal(matches)
}
var name_stat syscall.Stat_t
if err := syscall.Stat(matches[0], &name_stat); err != nil {
name_stat, err := os.Stat(matches[0])
if err != nil {
t.Fatal(err)
}
if name_stat.Mtim.Sec != long_stat.Mtim.Sec+10 {
if name_stat.ModTime().Unix() != long_stat.ModTime().Unix()+10 {
t.Errorf(".name file should show mtime+10")
}
if name_stat.Ctim.Sec != long_stat.Ctim.Sec+10 {
t.Errorf(".name file should show ctime+10")
}

// Check gocryptfs.diriv
if deterministic_names {
// No gocryptfs.diriv
return
}

// Check gocryptfs.diriv
var diriv_stat syscall.Stat_t
if err := syscall.Stat(workdirB+"/gocryptfs.diriv", &diriv_stat); err != nil {
diriv_stat, err := os.Stat(workdirB + "/gocryptfs.diriv")
if err != nil {
t.Fatal(err)
}
if diriv_stat.Mtim.Sec != workdirA_stat.Mtim.Sec+10 {
if diriv_stat.ModTime().Unix() != workdirA_stat.ModTime().Unix()+10 {
t.Errorf("diriv file should show mtime+10")
}
if diriv_stat.Ctim.Sec != workdirA_stat.Ctim.Sec+10 {
t.Errorf("diriv file should show ctime+10")
}
}

0 comments on commit a0105e6

Please sign in to comment.