ulimit_test.go 1.1 KB

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