aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_common_test.go
blob: 17268e484e6a9766fcc17b97653c13d082fe6204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package syscallcompat

import (
	"bytes"
	"os"
	"runtime"
	"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 {
			if targetLen > 1000 && runtime.GOOS == "darwin" {
				// Symlinks longer than 1024 (?) bytes are not supported on
				// MacOS
				continue
			}
			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)
		}
	}
}