docker_config_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package config
  2. import (
  3. "fmt"
  4. "strings"
  5. "testing"
  6. )
  7. func testContains(t *testing.T, s string, substrs ...string) {
  8. for _, substr := range substrs {
  9. if !strings.Contains(s, substr) {
  10. t.Fail()
  11. }
  12. }
  13. }
  14. func TestGenerateEngineOptsString(t *testing.T) {
  15. if len(generateEngineOptsSlice(EngineOpts{})) != 0 {
  16. t.Fail()
  17. }
  18. if len(generateEngineOptsSlice(EngineOpts{
  19. Host: []string{
  20. "",
  21. },
  22. })) != 0 {
  23. t.Fail()
  24. }
  25. if len(generateEngineOptsSlice(EngineOpts{
  26. LogOpts: map[string]string{
  27. "max-file": "",
  28. },
  29. })) != 0 {
  30. t.Fail()
  31. }
  32. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  33. Bridge: "bridge",
  34. })), "--bridge bridge")
  35. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  36. SelinuxEnabled: &[]bool{true}[0],
  37. })), "--selinux-enabled")
  38. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  39. SelinuxEnabled: &[]bool{false}[0],
  40. })), "--selinux-enabled=false")
  41. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  42. Host: []string{
  43. "unix:///var/run/system-docker.sock",
  44. "unix:///var/run/docker.sock",
  45. },
  46. })), "--host unix:///var/run/system-docker.sock", "--host unix:///var/run/docker.sock")
  47. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  48. LogOpts: map[string]string{
  49. "max-size": "25m",
  50. "max-file": "2",
  51. },
  52. })), "--log-opt max-size=25m", "--log-opt max-file=2")
  53. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  54. Bridge: "bridge",
  55. SelinuxEnabled: &[]bool{true}[0],
  56. LogOpts: map[string]string{
  57. "max-size": "25m",
  58. "max-file": "2",
  59. },
  60. })), "--bridge bridge", "--selinux-enabled", "--log-opt max-size=25m", "--log-opt max-file=2")
  61. }