2017-12-06 21:07:24 +01:00
|
|
|
package syscallcompat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadlinkat(t *testing.T) {
|
|
|
|
for _, targetLen := range []int{100, 500, 4000} {
|
|
|
|
target := string(bytes.Repeat([]byte("x"), targetLen))
|
2018-10-11 19:45:47 +02:00
|
|
|
err := syscall.Symlink(target, tmpDir+"/readlinkat")
|
2017-12-06 21:07:24 +01:00
|
|
|
if err != nil {
|
2018-10-11 19:45:47 +02:00
|
|
|
if targetLen > 1000 {
|
2018-02-28 20:40:08 +01:00
|
|
|
// Symlinks longer than 1024 (?) bytes are not supported on
|
2018-10-11 19:45:47 +02:00
|
|
|
// MacOS and XFS
|
|
|
|
t.Logf("skipping targetLen=%d: %v", targetLen, err)
|
2018-02-28 20:40:08 +01:00
|
|
|
continue
|
|
|
|
}
|
2018-10-11 19:45:47 +02:00
|
|
|
t.Fatalf("targetLen=%d: %v", targetLen, err)
|
2017-12-06 21:07:24 +01:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|