config_windows_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // +build windows
  2. package config
  3. import (
  4. "io/ioutil"
  5. "testing"
  6. "github.com/docker/docker/opts"
  7. "github.com/spf13/pflag"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. )
  11. func TestDaemonConfigurationMerge(t *testing.T) {
  12. f, err := ioutil.TempFile("", "docker-config-")
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. configFile := f.Name()
  17. f.Write([]byte(`
  18. {
  19. "debug": true,
  20. "log-opts": {
  21. "tag": "test_tag"
  22. }
  23. }`))
  24. f.Close()
  25. c := &Config{
  26. CommonConfig: CommonConfig{
  27. AutoRestart: true,
  28. LogConfig: LogConfig{
  29. Type: "syslog",
  30. Config: map[string]string{"tag": "test"},
  31. },
  32. },
  33. }
  34. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  35. var debug bool
  36. flags.BoolVarP(&debug, "debug", "D", false, "")
  37. flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "")
  38. cc, err := MergeDaemonConfigurations(c, flags, configFile)
  39. require.NoError(t, err)
  40. assert.True(t, cc.Debug)
  41. assert.True(t, cc.AutoRestart)
  42. expectedLogConfig := LogConfig{
  43. Type: "syslog",
  44. Config: map[string]string{"tag": "test_tag"},
  45. }
  46. assert.Equal(t, expectedLogConfig, cc.LogConfig)
  47. }