aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_common_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-12-06 21:07:24 +0100
committerJakob Unterwurzacher2017-12-06 21:07:24 +0100
commitf97494e89bff7b15d1be5f4b2d047382a54e6094 (patch)
treeacc6e2b5af46717c4cdb4d53cc0b5b543b8b8750 /internal/syscallcompat/sys_common_test.go
parent6beb45e5b74aa465136687f00f2b5a51bee90395 (diff)
syscallcompat: add Readlinkat
We need readlinkat to implement Readlink symlink-race-free.
Diffstat (limited to 'internal/syscallcompat/sys_common_test.go')
-rw-r--r--internal/syscallcompat/sys_common_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_common_test.go b/internal/syscallcompat/sys_common_test.go
new file mode 100644
index 0000000..bc694ba
--- /dev/null
+++ b/internal/syscallcompat/sys_common_test.go
@@ -0,0 +1,29 @@
+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)
+ }
+ }
+}