Merge pull request #43971 from thaJeztah/daemon_fix_hosts_validation_step1c3
daemon: use initialized config struct in more tests
This commit is contained in:
commit
61e5cf083a
2 changed files with 12 additions and 6 deletions
|
@ -12,12 +12,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultOptions(t *testing.T, configFile string) *daemonOptions {
|
func defaultOptions(t *testing.T, configFile string) *daemonOptions {
|
||||||
opts := newDaemonOptions(&config.Config{})
|
cfg, err := config.New()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
opts := newDaemonOptions(cfg)
|
||||||
opts.flags = &pflag.FlagSet{}
|
opts.flags = &pflag.FlagSet{}
|
||||||
opts.installFlags(opts.flags)
|
opts.installFlags(opts.flags)
|
||||||
if err := installConfigFlags(opts.daemonConfig, opts.flags); err != nil {
|
err = installConfigFlags(opts.daemonConfig, opts.flags)
|
||||||
t.Fatal(err)
|
assert.NilError(t, err)
|
||||||
}
|
|
||||||
defaultDaemonConfigFile, err := getDefaultDaemonConfigFile()
|
defaultDaemonConfigFile, err := getDefaultDaemonConfigFile()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
opts.flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "")
|
opts.flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "")
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
|
"github.com/imdario/mergo"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
|
@ -112,7 +113,8 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) {
|
||||||
file := fs.NewFile(t, "docker-config", fs.WithContent(data))
|
file := fs.NewFile(t, "docker-config", fs.WithContent(data))
|
||||||
defer file.Remove()
|
defer file.Remove()
|
||||||
|
|
||||||
c := &Config{}
|
c, err := New()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||||
shmSize := opts.MemBytes(DefaultShmSize)
|
shmSize := opts.MemBytes(DefaultShmSize)
|
||||||
|
@ -156,7 +158,10 @@ func TestUnixValidateConfigurationErrors(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.doc, func(t *testing.T) {
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
err := Validate(tc.config)
|
cfg, err := New()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Check(t, mergo.Merge(cfg, tc.config, mergo.WithOverride))
|
||||||
|
err = Validate(cfg)
|
||||||
assert.ErrorContains(t, err, tc.expectedErr)
|
assert.ErrorContains(t, err, tc.expectedErr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue