1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03:00

--max-concurrent-downloads,--max-concurrent-uploads must great than or equal to 0

Signed-off-by: chchliang <chen.chuanliang@zte.com.cn>
Upstream-commit: e59af2abe692a1b16e8d11e2698714cf3d77d8c8
Component: engine
This commit is contained in:
chchliang
2017-03-02 08:58:06 +08:00
parent e79e000efa
commit 7860655b94
2 changed files with 59 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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)