File: userns_linux_test.go

package info (click to toggle)
golang-github-moby-sys 0.0~git20241107.638aa7c-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 616 kB
  • sloc: makefile: 58
file content (34 lines) | stat: -rw-r--r-- 713 bytes parent folder | download
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
package userns

import "testing"

func TestUIDMapInUserNS(t *testing.T) {
	cases := []struct {
		s        string
		expected bool
	}{
		{
			s:        "         0          0 4294967295\n",
			expected: false,
		},
		{
			s:        "         0          0          1\n",
			expected: true,
		},
		{
			s:        "         0       1001          1\n         1     231072      65536\n",
			expected: true,
		},
		{
			// file exist but empty (the initial state when userns is created. see man 7 user_namespaces)
			s:        "",
			expected: true,
		},
	}
	for _, c := range cases {
		actual := uidMapInUserNS(c.s)
		if c.expected != actual {
			t.Fatalf("expected %v, got %v for %q", c.expected, actual, c.s)
		}
	}
}