github.com/hms58/moby@v1.13.1/runconfig/opts/ulimit_test.go (about) 1 package opts 2 3 import ( 4 "testing" 5 6 "github.com/docker/go-units" 7 ) 8 9 func TestUlimitOpt(t *testing.T) { 10 ulimitMap := map[string]*units.Ulimit{ 11 "nofile": {"nofile", 1024, 512}, 12 } 13 14 ulimitOpt := NewUlimitOpt(&ulimitMap) 15 16 expected := "[nofile=512:1024]" 17 if ulimitOpt.String() != expected { 18 t.Fatalf("Expected %v, got %v", expected, ulimitOpt) 19 } 20 21 // Valid ulimit append to opts 22 if err := ulimitOpt.Set("core=1024:1024"); err != nil { 23 t.Fatal(err) 24 } 25 26 // Invalid ulimit type returns an error and do not append to opts 27 if err := ulimitOpt.Set("notavalidtype=1024:1024"); err == nil { 28 t.Fatalf("Expected error on invalid ulimit type") 29 } 30 expected = "[nofile=512:1024 core=1024:1024]" 31 expected2 := "[core=1024:1024 nofile=512:1024]" 32 result := ulimitOpt.String() 33 if result != expected && result != expected2 { 34 t.Fatalf("Expected %v or %v, got %v", expected, expected2, ulimitOpt) 35 } 36 37 // And test GetList 38 ulimits := ulimitOpt.GetList() 39 if len(ulimits) != 2 { 40 t.Fatalf("Expected a ulimit list of 2, got %v", ulimits) 41 } 42 }