mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
--max-concurrent-downloads,--max-concurrent-uploads must great than or equal to 0
Signed-off-by: chchliang <chen.chuanliang@zte.com.cn>
This commit is contained in:
parent
9358189fa3
commit
e59af2abe6
2 changed files with 59 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue