sys: add missing pre-condition checks in tests
SetOOMScore requires both privileged (root) and non-user namespace, for negative values, so adjust the pre-conditions accordingly. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
badd60d3f6
commit
6e72715226
@ -23,11 +23,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/pkg/userns"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetPositiveOomScoreAdjustment(t *testing.T) {
|
func TestSetPositiveOomScoreAdjustment(t *testing.T) {
|
||||||
|
// Setting a *positive* OOM score adjust does not require privileged
|
||||||
_, adjustment, err := adjustOom(123)
|
_, adjustment, err := adjustOom(123)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@ -37,8 +39,8 @@ func TestSetPositiveOomScoreAdjustment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
|
func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
|
||||||
if !runningPrivileged() {
|
if !runningPrivileged() || userns.RunningInUserNS() {
|
||||||
t.Skip("Needs to be run as root")
|
t.Skip("requires root and not running in user namespace")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +53,8 @@ func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetNegativeOomScoreAdjustmentWhenUnprivilegedHasNoEffect(t *testing.T) {
|
func TestSetNegativeOomScoreAdjustmentWhenUnprivilegedHasNoEffect(t *testing.T) {
|
||||||
if runningPrivileged() {
|
if runningPrivileged() && !userns.RunningInUserNS() {
|
||||||
t.Skip("Needs to be run as non-root")
|
t.Skip("needs to be run as non-root or in user namespace")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user