daemon/config: verify that flags were set correctly in tests

To prevent (e.g.) introducing a typo in the flag-name and invalidating
the tests because of that.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-06-22 14:35:12 +02:00
parent f73aadb230
commit 751222d907
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -73,7 +73,7 @@ func TestDaemonConfigurationMergeConflicts(t *testing.T) {
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
flags.Bool("debug", false, "") flags.Bool("debug", false, "")
flags.Set("debug", "false") assert.Check(t, flags.Set("debug", "false"))
_, err = MergeDaemonConfigurations(&Config{}, flags, configFile) _, err = MergeDaemonConfigurations(&Config{}, flags, configFile)
if err == nil { if err == nil {
@ -128,7 +128,7 @@ func TestDaemonConfigurationMergeConflictsWithInnerStructs(t *testing.T) {
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
flags.String("tlscacert", "", "") flags.String("tlscacert", "", "")
flags.Set("tlscacert", "~/.docker/ca.pem") assert.Check(t, flags.Set("tlscacert", "~/.docker/ca.pem"))
_, err = MergeDaemonConfigurations(&Config{}, flags, configFile) _, err = MergeDaemonConfigurations(&Config{}, flags, configFile)
if err == nil { if err == nil {
@ -152,7 +152,7 @@ func TestDaemonConfigurationMergeDefaultAddressPools(t *testing.T) {
var conf = Config{} var conf = Config{}
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "") flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "")
flags.Set("default-address-pool", "base=10.123.0.0/16,size=24") assert.Check(t, flags.Set("default-address-pool", "base=10.123.0.0/16,size=24"))
config, err := MergeDaemonConfigurations(&conf, flags, emptyConfigFile.Path()) config, err := MergeDaemonConfigurations(&conf, flags, emptyConfigFile.Path())
assert.NilError(t, err) assert.NilError(t, err)
@ -173,7 +173,7 @@ func TestDaemonConfigurationMergeDefaultAddressPools(t *testing.T) {
var conf = Config{} var conf = Config{}
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "") flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "")
flags.Set("default-address-pool", "base=10.123.0.0/16,size=24") assert.Check(t, flags.Set("default-address-pool", "base=10.123.0.0/16,size=24"))
_, err := MergeDaemonConfigurations(&conf, flags, configFile.Path()) _, err := MergeDaemonConfigurations(&conf, flags, configFile.Path())
assert.ErrorContains(t, err, "the following directives are specified both as a flag and in the configuration file") assert.ErrorContains(t, err, "the following directives are specified both as a flag and in the configuration file")
@ -206,7 +206,7 @@ func TestFindConfigurationConflictsWithMergedValues(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
flags.Set("host", "unix:///var/run/docker.sock") assert.Check(t, flags.Set("host", "unix:///var/run/docker.sock"))
err = findConfigurationConflicts(config, flags) err = findConfigurationConflicts(config, flags)
if err == nil { if err == nil {
t.Fatal("expected error, got nil") t.Fatal("expected error, got nil")
@ -544,7 +544,7 @@ func TestReloadSetConfigFileNotExist(t *testing.T) {
configFile := "/tmp/blabla/not/exists/config.json" configFile := "/tmp/blabla/not/exists/config.json"
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
flags.String("config-file", "", "") flags.String("config-file", "", "")
flags.Set("config-file", configFile) assert.Check(t, flags.Set("config-file", configFile))
err := Reload(configFile, flags, func(c *Config) {}) err := Reload(configFile, flags, func(c *Config) {})
assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file")) assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file"))