config_common_unix_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // +build !windows
  2. package config
  3. import (
  4. "testing"
  5. "github.com/docker/docker/api/types"
  6. )
  7. func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
  8. testCases := []struct {
  9. config *Config
  10. }{
  11. // Can't override the stock runtime
  12. {
  13. config: &Config{
  14. CommonUnixConfig: CommonUnixConfig{
  15. Runtimes: map[string]types.Runtime{
  16. StockRuntimeName: {},
  17. },
  18. },
  19. },
  20. },
  21. // Default runtime should be present in runtimes
  22. {
  23. config: &Config{
  24. CommonUnixConfig: CommonUnixConfig{
  25. Runtimes: map[string]types.Runtime{
  26. "foo": {},
  27. },
  28. DefaultRuntime: "bar",
  29. },
  30. },
  31. },
  32. }
  33. for _, tc := range testCases {
  34. err := Validate(tc.config)
  35. if err == nil {
  36. t.Fatalf("expected error, got nil for config %v", tc.config)
  37. }
  38. }
  39. }
  40. func TestCommonUnixGetInitPath(t *testing.T) {
  41. testCases := []struct {
  42. config *Config
  43. expectedInitPath string
  44. }{
  45. {
  46. config: &Config{
  47. InitPath: "some-init-path",
  48. },
  49. expectedInitPath: "some-init-path",
  50. },
  51. {
  52. config: &Config{
  53. CommonUnixConfig: CommonUnixConfig{
  54. DefaultInitBinary: "foo-init-bin",
  55. },
  56. },
  57. expectedInitPath: "foo-init-bin",
  58. },
  59. {
  60. config: &Config{
  61. InitPath: "init-path-A",
  62. CommonUnixConfig: CommonUnixConfig{
  63. DefaultInitBinary: "init-path-B",
  64. },
  65. },
  66. expectedInitPath: "init-path-A",
  67. },
  68. {
  69. config: &Config{},
  70. expectedInitPath: "docker-init",
  71. },
  72. }
  73. for _, tc := range testCases {
  74. initPath := tc.config.GetInitPath()
  75. if initPath != tc.expectedInitPath {
  76. t.Fatalf("expected initPath to be %v, got %v", tc.expectedInitPath, initPath)
  77. }
  78. }
  79. }