utils_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, err := mergeLxcConfIntoOptions(hostConfig)
  14. if err != nil {
  15. t.Fatalf("Failed to merge Lxc Config ", err)
  16. }
  17. cpuset := out[0]
  18. if expected := "cgroups.cpuset=1,2"; cpuset != expected {
  19. t.Fatalf("expected %s got %s", expected, cpuset)
  20. }
  21. }
  22. func TestRemoveLocalDns(t *testing.T) {
  23. ns0 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\n"
  24. if result := utils.RemoveLocalDns([]byte(ns0)); result != nil {
  25. if ns0 != string(result) {
  26. t.Fatalf("Failed No Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  27. }
  28. }
  29. ns1 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\nnameserver 127.0.0.1\n"
  30. if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
  31. if ns0 != string(result) {
  32. t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  33. }
  34. }
  35. ns1 = "nameserver 10.16.60.14\nnameserver 127.0.0.1\nnameserver 10.16.60.21\n"
  36. if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
  37. if ns0 != string(result) {
  38. t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  39. }
  40. }
  41. ns1 = "nameserver 127.0.1.1\nnameserver 10.16.60.14\nnameserver 10.16.60.21\n"
  42. if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
  43. if ns0 != string(result) {
  44. t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
  45. }
  46. }
  47. }