2016-06-07 03:45:21 -04:00
|
|
|
// +build !windows,!solaris
|
|
|
|
|
|
|
|
// TODO: Create new file for Solaris which tests config parameters
|
|
|
|
// as described in daemon/config_solaris.go
|
2016-01-25 16:30:33 -05:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-01-23 06:23:07 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/daemon/config"
|
2016-06-22 18:36:51 -04:00
|
|
|
"github.com/docker/docker/pkg/testutil/tempfile"
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2016-01-25 16:30:33 -05:00
|
|
|
)
|
|
|
|
|
2016-03-11 22:31:08 -05:00
|
|
|
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
|
2016-06-22 18:36:51 -04:00
|
|
|
content := `{"log-opts": {"max-size": "1k"}}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
opts.common.Debug = true
|
|
|
|
opts.common.LogLevel = "info"
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, opts.flags.Set("selinux-enabled", "true"))
|
2016-06-22 18:36:51 -04:00
|
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, loadedConfig)
|
|
|
|
|
|
|
|
assert.True(t, loadedConfig.Debug)
|
|
|
|
assert.Equal(t, "info", loadedConfig.LogLevel)
|
|
|
|
assert.True(t, loadedConfig.EnableSelinuxSupport)
|
|
|
|
assert.Equal(t, "json-file", loadedConfig.LogConfig.Type)
|
|
|
|
assert.Equal(t, "1k", loadedConfig.LogConfig.Config["max-size"])
|
2016-03-11 22:31:08 -05:00
|
|
|
}
|
|
|
|
|
2016-01-25 16:30:33 -05:00
|
|
|
func TestLoadDaemonConfigWithNetwork(t *testing.T) {
|
2016-06-22 18:36:51 -04:00
|
|
|
content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-01-25 16:30:33 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, loadedConfig)
|
2016-01-25 16:30:33 -05:00
|
|
|
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.Equal(t, "127.0.0.2", loadedConfig.IP)
|
|
|
|
assert.Equal(t, "127.0.0.1", loadedConfig.DefaultIP.String())
|
2016-01-25 16:30:33 -05:00
|
|
|
}
|
2016-02-29 20:50:16 -05:00
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
|
2016-06-22 18:36:51 -04:00
|
|
|
content := `{
|
2016-02-29 20:50:16 -05:00
|
|
|
"cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"},
|
|
|
|
"log-opts": {"tag": "test"}
|
2016-06-22 18:36:51 -04:00
|
|
|
}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, loadedConfig)
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.NotNil(t, loadedConfig.ClusterOpts)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
|
|
|
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.Equal(t, expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"])
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.NotNil(t, loadedConfig.LogConfig.Config)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.Equal(t, "test", loadedConfig.LogConfig.Config["tag"])
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
|
2016-06-22 18:36:51 -04:00
|
|
|
content := `{ "userland-proxy": false }`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, loadedConfig)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.False(t, loadedConfig.EnableUserlandProxy)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
|
|
|
// make sure reloading doesn't generate configuration
|
|
|
|
// conflicts after normalizing boolean values.
|
2017-01-23 06:23:07 -05:00
|
|
|
reload := func(reloadedConfig *config.Config) {
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.False(t, reloadedConfig.EnableUserlandProxy)
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, config.Reload(opts.configFile, opts.flags, reload))
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
|
2016-06-22 18:36:51 -04:00
|
|
|
tempFile := tempfile.NewTempFile(t, "config", `{}`)
|
|
|
|
defer tempFile.Remove()
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, loadedConfig)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.True(t, loadedConfig.EnableUserlandProxy)
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
2016-07-18 17:48:26 -04:00
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
|
2016-06-23 11:25:51 -04:00
|
|
|
content := `{"disable-legacy-registry": true}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-07-18 17:48:26 -04:00
|
|
|
|
2016-06-23 11:25:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, loadedConfig)
|
|
|
|
assert.True(t, loadedConfig.V2Only)
|
2016-07-18 17:48:26 -04:00
|
|
|
}
|