summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/limits/limits_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/limits/limits_test.go')
-rw-r--r--pkg/sentry/limits/limits_test.go30
1 files changed, 18 insertions, 12 deletions
diff --git a/pkg/sentry/limits/limits_test.go b/pkg/sentry/limits/limits_test.go
index d41f62554..945428163 100644
--- a/pkg/sentry/limits/limits_test.go
+++ b/pkg/sentry/limits/limits_test.go
@@ -20,18 +20,24 @@ import (
)
func TestSet(t *testing.T) {
- ls := NewLimitSet()
- ls.Set(1, Limit{Cur: 50, Max: 50})
- if _, err := ls.Set(1, Limit{Cur: 20, Max: 50}); err != nil {
- t.Fatalf("Tried to lower Limit to valid new value: got %v, wanted nil", err)
- }
- if _, err := ls.Set(1, Limit{Cur: 20, Max: 60}); err != syscall.EPERM {
- t.Fatalf("Tried to raise limit.Max to invalid higher value: got %v, wanted syscall.EPERM", err)
- }
- if _, err := ls.Set(1, Limit{Cur: 60, Max: 50}); err != syscall.EINVAL {
- t.Fatalf("Tried to raise limit.Cur to invalid higher value: got %v, wanted syscall.EINVAL", err)
+ testCases := []struct {
+ limit Limit
+ privileged bool
+ expectedErr error
+ }{
+ {limit: Limit{Cur: 50, Max: 50}, privileged: false, expectedErr: nil},
+ {limit: Limit{Cur: 20, Max: 50}, privileged: false, expectedErr: nil},
+ {limit: Limit{Cur: 20, Max: 60}, privileged: false, expectedErr: syscall.EPERM},
+ {limit: Limit{Cur: 60, Max: 50}, privileged: false, expectedErr: syscall.EINVAL},
+ {limit: Limit{Cur: 11, Max: 10}, privileged: false, expectedErr: syscall.EINVAL},
+ {limit: Limit{Cur: 20, Max: 60}, privileged: true, expectedErr: nil},
}
- if _, err := ls.Set(1, Limit{Cur: 11, Max: 10}); err != syscall.EINVAL {
- t.Fatalf("Tried to set new limit with Cur > Max: got %v, wanted syscall.EINVAL", err)
+
+ ls := NewLimitSet()
+ for _, tc := range testCases {
+ if _, err := ls.Set(1, tc.limit, tc.privileged); err != tc.expectedErr {
+ t.Fatalf("Tried to set Limit to %+v and privilege %t: got %v, wanted %v", tc.limit, tc.privileged, err, tc.expectedErr)
+ }
}
+
}