diff --git a/daemon/config/config.go b/daemon/config/config.go index 63a5fd3643..5c103ec4aa 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -276,7 +276,7 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config } if err := Validate(fileConfig); err != nil { - return nil, fmt.Errorf("file configuration validation failed (%v)", err) + return nil, fmt.Errorf("configuration validation from file failed (%v)", err) } // merge flags configuration on top of the file configuration @@ -287,7 +287,7 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config // We need to validate again once both fileConfig and flagsConfig // have been merged if err := Validate(fileConfig); err != nil { - return nil, fmt.Errorf("file configuration validation failed (%v)", err) + return nil, fmt.Errorf("merged configuration validation from file and command line flags failed (%v)", err) } return fileConfig, nil @@ -459,14 +459,12 @@ func Validate(config *Config) error { return err } } - // validate MaxConcurrentDownloads - if config.IsValueSet("max-concurrent-downloads") && config.MaxConcurrentDownloads != nil && *config.MaxConcurrentDownloads < 0 { + if config.MaxConcurrentDownloads != nil && *config.MaxConcurrentDownloads < 0 { return fmt.Errorf("invalid max concurrent downloads: %d", *config.MaxConcurrentDownloads) } - // validate MaxConcurrentUploads - if config.IsValueSet("max-concurrent-uploads") && config.MaxConcurrentUploads != nil && *config.MaxConcurrentUploads < 0 { + if config.MaxConcurrentUploads != nil && *config.MaxConcurrentUploads < 0 { return fmt.Errorf("invalid max concurrent uploads: %d", *config.MaxConcurrentUploads) } diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index 5bddac650c..7508c213c4 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -103,6 +103,38 @@ func TestDaemonConfigurationMergeConflicts(t *testing.T) { } } +func TestDaemonConfigurationMergeConcurrent(t *testing.T) { + f, err := ioutil.TempFile("", "docker-config-") + if err != nil { + t.Fatal(err) + } + + configFile := f.Name() + f.Write([]byte(`{"max-concurrent-downloads": 1}`)) + f.Close() + + _, err = MergeDaemonConfigurations(&Config{}, nil, configFile) + if err != nil { + t.Fatal("expected error, got nil") + } +} + +func TestDaemonConfigurationMergeConcurrentError(t *testing.T) { + f, err := ioutil.TempFile("", "docker-config-") + if err != nil { + t.Fatal(err) + } + + configFile := f.Name() + f.Write([]byte(`{"max-concurrent-downloads": -1}`)) + f.Close() + + _, err = MergeDaemonConfigurations(&Config{}, nil, configFile) + if err == nil { + t.Fatalf("expected no error, got error %v", err) + } +} + func TestDaemonConfigurationMergeConflictsWithInnerStructs(t *testing.T) { f, err := ioutil.TempFile("", "docker-config-") if err != nil { @@ -240,6 +272,7 @@ func TestValidateConfigurationErrors(t *testing.T) { } func TestValidateConfiguration(t *testing.T) { + minusNumber := 4 testCases := []struct { config *Config }{ @@ -264,6 +297,28 @@ func TestValidateConfiguration(t *testing.T) { }, }, }, + { + config: &Config{ + CommonConfig: CommonConfig{ + MaxConcurrentDownloads: &minusNumber, + // This is weird... + ValuesSet: map[string]interface{}{ + "max-concurrent-downloads": -1, + }, + }, + }, + }, + { + config: &Config{ + CommonConfig: CommonConfig{ + MaxConcurrentUploads: &minusNumber, + // This is weird... + ValuesSet: map[string]interface{}{ + "max-concurrent-uploads": -1, + }, + }, + }, + }, } for _, tc := range testCases { err := Validate(tc.config)