github.com/apptainer/singularity@v3.1.1+incompatible/pkg/util/rlimit/rlimit_linux_test.go (about) 1 // Copyright (c) 2018, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package rlimit 7 8 import ( 9 "testing" 10 11 "github.com/sylabs/singularity/internal/pkg/test" 12 ) 13 14 func TestGetSet(t *testing.T) { 15 test.DropPrivilege(t) 16 defer test.ResetPrivilege(t) 17 18 cur, max, err := Get("RLIMIT_NOFILE") 19 if err != nil { 20 t.Error(err) 21 } 22 23 if err := Set("RLIMIT_NOFILE", cur, max); err != nil { 24 t.Error(err) 25 } 26 27 max++ 28 29 if err := Set("RLIMIT_NOFILE", cur, max); err == nil { 30 t.Errorf("process doesn't have privileges to do that") 31 } 32 33 cur, max, err = Get("RLIMIT_FAKE") 34 if err == nil { 35 t.Errorf("resource limit RLIMIT_FAKE doesn't exist") 36 } 37 38 if err := Set("RLIMIT_FAKE", cur, max); err == nil { 39 t.Errorf("resource limit RLIMIT_FAKE doesn't exist") 40 } 41 }