2018-02-05 21:05:59 +00:00
|
|
|
package opts // import "github.com/docker/docker/opts"
|
2015-07-12 08:33:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-05 14:37:47 +00:00
|
|
|
units "github.com/docker/go-units"
|
2015-07-12 08:33:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUlimitOpt(t *testing.T) {
|
2015-12-21 20:06:46 +00:00
|
|
|
ulimitMap := map[string]*units.Ulimit{
|
2019-08-06 19:08:07 +00:00
|
|
|
"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
|
2015-07-12 08:33:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-01 14:00:43 +00:00
|
|
|
ulimitOpt := NewUlimitOpt(&ulimitMap)
|
2015-07-12 08:33:30 +00:00
|
|
|
|
|
|
|
expected := "[nofile=512:1024]"
|
|
|
|
if ulimitOpt.String() != expected {
|
|
|
|
t.Fatalf("Expected %v, got %v", expected, ulimitOpt)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid ulimit append to opts
|
|
|
|
if err := ulimitOpt.Set("core=1024:1024"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid ulimit type returns an error and do not append to opts
|
|
|
|
if err := ulimitOpt.Set("notavalidtype=1024:1024"); err == nil {
|
|
|
|
t.Fatalf("Expected error on invalid ulimit type")
|
|
|
|
}
|
|
|
|
expected = "[nofile=512:1024 core=1024:1024]"
|
|
|
|
expected2 := "[core=1024:1024 nofile=512:1024]"
|
|
|
|
result := ulimitOpt.String()
|
|
|
|
if result != expected && result != expected2 {
|
|
|
|
t.Fatalf("Expected %v or %v, got %v", expected, expected2, ulimitOpt)
|
|
|
|
}
|
|
|
|
|
|
|
|
// And test GetList
|
|
|
|
ulimits := ulimitOpt.GetList()
|
|
|
|
if len(ulimits) != 2 {
|
|
|
|
t.Fatalf("Expected a ulimit list of 2, got %v", ulimits)
|
|
|
|
}
|
|
|
|
}
|