File: linux_test.go

package info (click to toggle)
runc 1.0.0~rc93%2Bds1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 3,172 kB
  • sloc: sh: 1,679; ansic: 1,039; makefile: 139
file content (45 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (4)
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
36
37
38
39
40
41
42
43
44
45
// +build linux

package system

import (
	"strings"
	"testing"

	"github.com/opencontainers/runc/libcontainer/user"
)

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 {
		uidmap, err := user.ParseIDMap(strings.NewReader(c.s))
		if err != nil {
			t.Fatal(err)
		}
		actual := UIDMapInUserNS(uidmap)
		if c.expected != actual {
			t.Fatalf("expected %v, got %v for %q", c.expected, actual, c.s)
		}
	}
}