2015-02-11 19:21:38 +00:00
|
|
|
package ulimit
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2015-03-25 23:59:40 +00:00
|
|
|
func TestParseValid(t *testing.T) {
|
|
|
|
u1 := &Ulimit{"nofile", 1024, 512}
|
2015-03-26 03:43:23 +00:00
|
|
|
if u2, _ := Parse("nofile=512:1024"); *u1 != *u2 {
|
|
|
|
t.Fatalf("expected %q, but got %q", u1, u2)
|
2015-03-25 23:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:21:38 +00: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 23:39:05 +00: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)
|
|
|
|
}
|
|
|
|
}
|