2015-02-11 14:21:38 -05:00
|
|
|
package ulimit
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2015-03-25 19:59:40 -04:00
|
|
|
func TestParseValid(t *testing.T) {
|
|
|
|
u1 := &Ulimit{"nofile", 1024, 512}
|
2015-03-25 23:43:23 -04:00
|
|
|
if u2, _ := Parse("nofile=512:1024"); *u1 != *u2 {
|
|
|
|
t.Fatalf("expected %q, but got %q", u1, u2)
|
2015-03-25 19:59:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:21:38 -05:00
|
|
|
func TestParseInvalidLimitType(t *testing.T) {
|
|
|
|
if _, err := Parse("notarealtype=1024:1024"); err == nil {
|
|
|
|
t.Fatalf("expected error on invalid ulimit type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseBadFormat(t *testing.T) {
|
|
|
|
if _, err := Parse("nofile:1024:1024"); err == nil {
|
|
|
|
t.Fatal("expected error on bad syntax")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := Parse("nofile"); err == nil {
|
|
|
|
t.Fatal("expected error on bad syntax")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := Parse("nofile="); err == nil {
|
|
|
|
t.Fatal("expected error on bad syntax")
|
|
|
|
}
|
|
|
|
if _, err := Parse("nofile=:"); err == nil {
|
|
|
|
t.Fatal("expected error on bad syntax")
|
|
|
|
}
|
|
|
|
if _, err := Parse("nofile=:1024"); err == nil {
|
|
|
|
t.Fatal("expected error on bad syntax")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseHardLessThanSoft(t *testing.T) {
|
|
|
|
if _, err := Parse("nofile:1024:1"); err == nil {
|
|
|
|
t.Fatal("expected error on hard limit less than soft limit")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseInvalidValueType(t *testing.T) {
|
|
|
|
if _, err := Parse("nofile:asdf"); err == nil {
|
|
|
|
t.Fatal("expected error on bad value type")
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 19:39:05 -04:00
|
|
|
|
|
|
|
func TestStringOutput(t *testing.T) {
|
|
|
|
u := &Ulimit{"nofile", 1024, 512}
|
|
|
|
if s := u.String(); s != "nofile=512:1024" {
|
|
|
|
t.Fatal("expected String to return nofile=512:1024, but got", s)
|
|
|
|
}
|
|
|
|
}
|