From 751222d907e169c9e191d27ef7820d15cb740ff6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 22 Jun 2022 14:35:12 +0200 Subject: [PATCH] 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 --- daemon/config/config_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index 2841af6c77..c9ea22c442 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -73,7 +73,7 @@ func TestDaemonConfigurationMergeConflicts(t *testing.T) { flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.Bool("debug", false, "") - flags.Set("debug", "false") + assert.Check(t, flags.Set("debug", "false")) _, err = MergeDaemonConfigurations(&Config{}, flags, configFile) if err == nil { @@ -128,7 +128,7 @@ func TestDaemonConfigurationMergeConflictsWithInnerStructs(t *testing.T) { flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.String("tlscacert", "", "") - flags.Set("tlscacert", "~/.docker/ca.pem") + assert.Check(t, flags.Set("tlscacert", "~/.docker/ca.pem")) _, err = MergeDaemonConfigurations(&Config{}, flags, configFile) if err == nil { @@ -152,7 +152,7 @@ func TestDaemonConfigurationMergeDefaultAddressPools(t *testing.T) { var conf = Config{} flags := pflag.NewFlagSet("test", pflag.ContinueOnError) 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()) assert.NilError(t, err) @@ -173,7 +173,7 @@ func TestDaemonConfigurationMergeDefaultAddressPools(t *testing.T) { var conf = Config{} flags := pflag.NewFlagSet("test", pflag.ContinueOnError) 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()) 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) } - flags.Set("host", "unix:///var/run/docker.sock") + assert.Check(t, flags.Set("host", "unix:///var/run/docker.sock")) err = findConfigurationConflicts(config, flags) if err == nil { t.Fatal("expected error, got nil") @@ -544,7 +544,7 @@ func TestReloadSetConfigFileNotExist(t *testing.T) { configFile := "/tmp/blabla/not/exists/config.json" flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.String("config-file", "", "") - flags.Set("config-file", configFile) + assert.Check(t, flags.Set("config-file", configFile)) err := Reload(configFile, flags, func(c *Config) {}) assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file"))