container/capability: check CAP_TO_INDEX and CAP_TO_MASK
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m14s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 4m24s
Test / Hakurei (race detector) (push) Successful in 5m2s
Test / Flake checks (push) Successful in 1m27s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m14s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 4m24s
Test / Hakurei (race detector) (push) Successful in 5m2s
Test / Flake checks (push) Successful in 1m27s
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
b4c018da8f
commit
022cc26b2e
41
container/capability_test.go
Normal file
41
container/capability_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package container
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCapToIndex(t *testing.T) {
|
||||||
|
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) {
|
||||||
|
if got := capToIndex(tc.cap); got != tc.want {
|
||||||
|
t.Errorf("capToIndex: %#x, want %#x", got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCapToMask(t *testing.T) {
|
||||||
|
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) {
|
||||||
|
if got := capToMask(tc.cap); got != tc.want {
|
||||||
|
t.Errorf("capToMask: %#x, want %#x", got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user