2016-08-10 06:52:06 -04:00
|
|
|
// +build windows
|
|
|
|
|
2017-01-23 06:23:07 -05:00
|
|
|
package config
|
2016-08-10 06:52:06 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
2017-04-12 03:26:42 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/opts"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2016-08-10 06:52:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDaemonConfigurationMerge(t *testing.T) {
|
|
|
|
f, err := ioutil.TempFile("", "docker-config-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
configFile := f.Name()
|
|
|
|
|
|
|
|
f.Write([]byte(`
|
|
|
|
{
|
|
|
|
"debug": true,
|
|
|
|
"log-opts": {
|
|
|
|
"tag": "test_tag"
|
|
|
|
}
|
|
|
|
}`))
|
|
|
|
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
c := &Config{
|
|
|
|
CommonConfig: CommonConfig{
|
|
|
|
AutoRestart: true,
|
|
|
|
LogConfig: LogConfig{
|
|
|
|
Type: "syslog",
|
|
|
|
Config: map[string]string{"tag": "test"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-12 03:26:42 -04:00
|
|
|
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
|
|
|
var debug bool
|
|
|
|
flags.BoolVarP(&debug, "debug", "D", false, "")
|
|
|
|
flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "")
|
|
|
|
|
|
|
|
cc, err := MergeDaemonConfigurations(c, flags, configFile)
|
|
|
|
require.NoError(t, err)
|
2016-08-10 06:52:06 -04:00
|
|
|
|
2017-04-12 03:26:42 -04:00
|
|
|
assert.True(t, cc.Debug)
|
|
|
|
assert.True(t, cc.AutoRestart)
|
|
|
|
|
|
|
|
expectedLogConfig := LogConfig{
|
|
|
|
Type: "syslog",
|
|
|
|
Config: map[string]string{"tag": "test_tag"},
|
2016-08-10 06:52:06 -04:00
|
|
|
}
|
2017-04-12 03:26:42 -04:00
|
|
|
|
|
|
|
assert.Equal(t, expectedLogConfig, cc.LogConfig)
|
2016-08-10 06:52:06 -04:00
|
|
|
}
|