tests: add TestHaveDotdot

As discovered by xfstests generic/401 [1], during the move to
the v2 api we seem to have lost the "." and ".." directory
entries.

[1]: 4ef5b032bc/screenlog.0 (L520)
This commit is contained in:
Jakob Unterwurzacher 2021-05-23 11:08:03 +02:00
parent 1d2ac1e589
commit 7d72baca69
1 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package matrix
import (
"fmt"
"os"
"os/exec"
"syscall"
"testing"
@ -48,3 +49,24 @@ func TestRmdirPerms(t *testing.T) {
}
}
}
// TestHaveDotdot checks that we have "." and ".." in a directory.
// (gocryptfs v2.0-beta1 did not!)
func TestHaveDotdot(t *testing.T) {
dir1 := test_helpers.DefaultPlainDir + "/TestHaveDotdot"
err := os.Mkdir(dir1, 0700)
if err != nil {
t.Fatal(err)
}
// All Go readdir functions filter out "." and "..".
// Fall back to "ls -a" which does not.
out, err := exec.Command("ls", "-a", dir1).CombinedOutput()
if err != nil {
t.Fatal(err)
}
have := string(out)
want := ".\n..\n"
if have != want {
t.Errorf("have=%q want=%q", have, want)
}
}