utils_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package daemon
  2. import (
  3. "testing"
  4. "github.com/docker/docker/runconfig"
  5. "github.com/docker/docker/utils"
  6. )
  7. func TestMergeLxcConfig(t *testing.T) {
  8. hostConfig := &runconfig.HostConfig{
  9. LxcConf: []utils.KeyValuePair{
  10. {Key: "lxc.cgroups.cpuset", Value: "1,2"},
  11. },
  12. }
  13. out := mergeLxcConfIntoOptions(hostConfig)
  14. cpuset := out[0]
  15. if expected := "cgroups.cpuset=1,2"; cpuset != expected {
  16. t.Fatalf("expected %s got %s", expected, cpuset)
  17. }
  18. }
  19. func TestRemoveLocalDns(t *testing.T) {
  20. ns0 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\n"
  21. if result := utils.RemoveLocalDns([]byte(ns0)); result != nil {
  22. if ns0 != string(result) {
  23. t.Fatalf("Failed No Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  24. }
  25. }
  26. ns1 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\nnameserver 127.0.0.1\n"
  27. if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
  28. if ns0 != string(result) {
  29. t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  30. }
  31. }
  32. ns1 = "nameserver 10.16.60.14\nnameserver 127.0.0.1\nnameserver 10.16.60.21\n"
  33. if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
  34. if ns0 != string(result) {
  35. t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  36. }
  37. }
  38. ns1 = "nameserver 127.0.1.1\nnameserver 10.16.60.14\nnameserver 10.16.60.21\n"
  39. if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
  40. if ns0 != string(result) {
  41. t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  42. }
  43. }
  44. }