libgocryptfs/internal/syscallcompat/sys_common_test.go
Jakob Unterwurzacher f97494e89b syscallcompat: add Readlinkat
We need readlinkat to implement Readlink
symlink-race-free.
2017-12-06 21:07:24 +01:00

30 lines
570 B
Go

package syscallcompat
import (
"bytes"
"os"
"syscall"
"testing"
)
func TestReadlinkat(t *testing.T) {
for _, targetLen := range []int{100, 500, 4000} {
target := string(bytes.Repeat([]byte("x"), targetLen))
err := os.Symlink(target, tmpDir+"/readlinkat")
if err != nil {
t.Fatal(err)
}
target2, err := Readlinkat(tmpDirFd, "readlinkat")
if err != nil {
t.Fatal(err)
}
if target != target2 {
t.Errorf("target=%q != target2=%q", target, target2)
}
err = syscall.Unlink(tmpDir + "/readlinkat")
if err != nil {
t.Fatal(err)
}
}
}