mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
This type is included in various types used in the API, but comes from a separate module. The go-units module may be moving to the moby org, and it is yet to be decided if the Ulimit type is a good fit for that module (which deals with more generic units, such as "size" and "duration" otherwise). This patch introduces an alias to help during the transition of this type to it's new location. The alias makes sure that existing code continues to work (at least for now), but we need to start updating such code after this PR is merged. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package opts // import "github.com/docker/docker/opts"
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
)
|
|
|
|
func TestUlimitOpt(t *testing.T) {
|
|
ulimitMap := map[string]*container.Ulimit{
|
|
"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
|
|
}
|
|
|
|
ulimitOpt := NewUlimitOpt(&ulimitMap)
|
|
|
|
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)
|
|
}
|
|
}
|