aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/capability_test.go
blob: 9494480aff5ff3ac78e872e014876b7cee75d313 (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
36
37
38
39
40
41
42
43
44
45
46
47
package container

import "testing"

func TestCapToIndex(t *testing.T) {
	t.Parallel()

	testCases := []struct {
		name string
		cap  uintptr
		want uintptr
	}{
		{"CAP_SYS_ADMIN", CAP_SYS_ADMIN, 0},
		{"CAP_SETPCAP", CAP_SETPCAP, 0},
		{"CAP_DAC_OVERRIDE", CAP_DAC_OVERRIDE, 0},
	}
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()
			if got := capToIndex(tc.cap); got != tc.want {
				t.Errorf("capToIndex: %#x, want %#x", got, tc.want)
			}
		})
	}
}

func TestCapToMask(t *testing.T) {
	t.Parallel()

	testCases := []struct {
		name string
		cap  uintptr
		want uint32
	}{
		{"CAP_SYS_ADMIN", CAP_SYS_ADMIN, 0x200000},
		{"CAP_SETPCAP", CAP_SETPCAP, 0x100},
		{"CAP_DAC_OVERRIDE", CAP_DAC_OVERRIDE, 0x2},
	}
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()
			if got := capToMask(tc.cap); got != tc.want {
				t.Errorf("capToMask: %#x, want %#x", got, tc.want)
			}
		})
	}
}