config_common_unix_test.go 1.7 KB

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