docker_config_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  19. Bridge: "bridge",
  20. })), "--bridge bridge")
  21. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  22. SelinuxEnabled: &[]bool{true}[0],
  23. })), "--selinux-enabled")
  24. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  25. SelinuxEnabled: &[]bool{false}[0],
  26. })), "--selinux-enabled=false")
  27. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  28. LogOpts: map[string]string{
  29. "max-size": "25m",
  30. "max-file": "2",
  31. },
  32. })), "--log-opt max-size=25m", "--log-opt max-file=2")
  33. testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
  34. Bridge: "bridge",
  35. SelinuxEnabled: &[]bool{true}[0],
  36. LogOpts: map[string]string{
  37. "max-size": "25m",
  38. "max-file": "2",
  39. },
  40. })), "--bridge bridge", "--selinux-enabled", "--log-opt max-size=25m", "--log-opt max-file=2")
  41. }