@@ -66,9 +66,66 @@ func TestParseUlimitInvalidValueType(t *testing.T) {
6666 }
6767}
6868
69+ func TestParseUlimitTooManyValueArgs (t * testing.T ) {
70+ if _ , err := ParseUlimit ("nofile=1024:1:50" ); err == nil {
71+ t .Fatalf ("expected error on more than two value arguments" )
72+ }
73+ }
74+
6975func TestUlimitStringOutput (t * testing.T ) {
7076 u := & Ulimit {"nofile" , 1024 , 512 }
7177 if s := u .String (); s != "nofile=512:1024" {
7278 t .Fatal ("expected String to return nofile=512:1024, but got" , s )
7379 }
7480}
81+
82+ func TestGetRlimit (t * testing.T ) {
83+ tt := []struct {
84+ ulimit Ulimit
85+ rlimit Rlimit
86+ }{
87+ {Ulimit {"core" , 10 , 12 }, Rlimit {rlimitCore , 10 , 12 }},
88+ {Ulimit {"cpu" , 1 , 10 }, Rlimit {rlimitCPU , 1 , 10 }},
89+ {Ulimit {"data" , 5 , 0 }, Rlimit {rlimitData , 5 , 0 }},
90+ {Ulimit {"fsize" , 2 , 2 }, Rlimit {rlimitFsize , 2 , 2 }},
91+ {Ulimit {"locks" , 0 , 0 }, Rlimit {rlimitLocks , 0 , 0 }},
92+ {Ulimit {"memlock" , 10 , 10 }, Rlimit {rlimitMemlock , 10 , 10 }},
93+ {Ulimit {"msgqueue" , 9 , 1 }, Rlimit {rlimitMsgqueue , 9 , 1 }},
94+ {Ulimit {"nice" , 9 , 9 }, Rlimit {rlimitNice , 9 , 9 }},
95+ {Ulimit {"nofile" , 4 , 100 }, Rlimit {rlimitNofile , 4 , 100 }},
96+ {Ulimit {"nproc" , 5 , 5 }, Rlimit {rlimitNproc , 5 , 5 }},
97+ {Ulimit {"rss" , 0 , 5 }, Rlimit {rlimitRss , 0 , 5 }},
98+ {Ulimit {"rtprio" , 100 , 65 }, Rlimit {rlimitRtprio , 100 , 65 }},
99+ {Ulimit {"rttime" , 55 , 102 }, Rlimit {rlimitRttime , 55 , 102 }},
100+ {Ulimit {"sigpending" , 14 , 20 }, Rlimit {rlimitSigpending , 14 , 20 }},
101+ {Ulimit {"stack" , 1 , 1 }, Rlimit {rlimitStack , 1 , 1 }},
102+ }
103+
104+ for _ , te := range tt {
105+ res , err := te .ulimit .GetRlimit ()
106+ if err != nil {
107+ t .Errorf ("expected not to fail: %s" , err )
108+ }
109+ if res .Type != te .rlimit .Type {
110+ t .Errorf ("expected Type to be %d but got %d" ,
111+ te .rlimit .Type , res .Type )
112+ }
113+ if res .Soft != te .rlimit .Soft {
114+ t .Errorf ("expected Soft to be %d but got %d" ,
115+ te .rlimit .Soft , res .Soft )
116+ }
117+ if res .Hard != te .rlimit .Hard {
118+ t .Errorf ("expected Hard to be %d but got %d" ,
119+ te .rlimit .Hard , res .Hard )
120+ }
121+
122+ }
123+ }
124+
125+ func TestGetRlimitBadUlimitName (t * testing.T ) {
126+ name := "bla"
127+ uLimit := Ulimit {name , 0 , 0 }
128+ if _ , err := uLimit .GetRlimit (); err == nil {
129+ t .Error ("expected error on bad Ulimit name" )
130+ }
131+ }
0 commit comments