Skip to content

Commit

Permalink
sys: add missing pre-condition checks in tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thaJeztah committed Apr 7, 2021
1 parent badd60d commit 6e72715
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sys/oom_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (
"testing"
"time"

"github.com/containerd/containerd/pkg/userns"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestSetPositiveOomScoreAdjustment(t *testing.T) {
// Setting a *positive* OOM score adjust does not require privileged
_, adjustment, err := adjustOom(123)
if err != nil {
t.Error(err)
Expand All @@ -37,8 +39,8 @@ func TestSetPositiveOomScoreAdjustment(t *testing.T) {
}

func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
if !runningPrivileged() {
t.Skip("Needs to be run as root")
if !runningPrivileged() || userns.RunningInUserNS() {
t.Skip("requires root and not running in user namespace")
return
}

Expand All @@ -51,8 +53,8 @@ func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
}

func TestSetNegativeOomScoreAdjustmentWhenUnprivilegedHasNoEffect(t *testing.T) {
if runningPrivileged() {
t.Skip("Needs to be run as non-root")
if runningPrivileged() && !userns.RunningInUserNS() {
t.Skip("needs to be run as non-root or in user namespace")
return
}

Expand Down

0 comments on commit 6e72715

Please sign in to comment.