Signed-off-by: chchliang <chen.chuanliang@zte.com.cn>
| ... | ... |
@@ -276,7 +276,7 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config |
| 276 | 276 |
} |
| 277 | 277 |
|
| 278 | 278 |
if err := Validate(fileConfig); err != nil {
|
| 279 |
- return nil, fmt.Errorf("file configuration validation failed (%v)", err)
|
|
| 279 |
+ return nil, fmt.Errorf("configuration validation from file failed (%v)", err)
|
|
| 280 | 280 |
} |
| 281 | 281 |
|
| 282 | 282 |
// merge flags configuration on top of the file configuration |
| ... | ... |
@@ -287,7 +287,7 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config |
| 287 | 287 |
// We need to validate again once both fileConfig and flagsConfig |
| 288 | 288 |
// have been merged |
| 289 | 289 |
if err := Validate(fileConfig); err != nil {
|
| 290 |
- return nil, fmt.Errorf("file configuration validation failed (%v)", err)
|
|
| 290 |
+ return nil, fmt.Errorf("merged configuration validation from file and command line flags failed (%v)", err)
|
|
| 291 | 291 |
} |
| 292 | 292 |
|
| 293 | 293 |
return fileConfig, nil |
| ... | ... |
@@ -459,14 +459,12 @@ func Validate(config *Config) error {
|
| 459 | 459 |
return err |
| 460 | 460 |
} |
| 461 | 461 |
} |
| 462 |
- |
|
| 463 | 462 |
// validate MaxConcurrentDownloads |
| 464 |
- if config.IsValueSet("max-concurrent-downloads") && config.MaxConcurrentDownloads != nil && *config.MaxConcurrentDownloads < 0 {
|
|
| 463 |
+ if config.MaxConcurrentDownloads != nil && *config.MaxConcurrentDownloads < 0 {
|
|
| 465 | 464 |
return fmt.Errorf("invalid max concurrent downloads: %d", *config.MaxConcurrentDownloads)
|
| 466 | 465 |
} |
| 467 |
- |
|
| 468 | 466 |
// validate MaxConcurrentUploads |
| 469 |
- if config.IsValueSet("max-concurrent-uploads") && config.MaxConcurrentUploads != nil && *config.MaxConcurrentUploads < 0 {
|
|
| 467 |
+ if config.MaxConcurrentUploads != nil && *config.MaxConcurrentUploads < 0 {
|
|
| 470 | 468 |
return fmt.Errorf("invalid max concurrent uploads: %d", *config.MaxConcurrentUploads)
|
| 471 | 469 |
} |
| 472 | 470 |
|
| ... | ... |
@@ -103,6 +103,38 @@ func TestDaemonConfigurationMergeConflicts(t *testing.T) {
|
| 103 | 103 |
} |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 |
+func TestDaemonConfigurationMergeConcurrent(t *testing.T) {
|
|
| 107 |
+ f, err := ioutil.TempFile("", "docker-config-")
|
|
| 108 |
+ if err != nil {
|
|
| 109 |
+ t.Fatal(err) |
|
| 110 |
+ } |
|
| 111 |
+ |
|
| 112 |
+ configFile := f.Name() |
|
| 113 |
+ f.Write([]byte(`{"max-concurrent-downloads": 1}`))
|
|
| 114 |
+ f.Close() |
|
| 115 |
+ |
|
| 116 |
+ _, err = MergeDaemonConfigurations(&Config{}, nil, configFile)
|
|
| 117 |
+ if err != nil {
|
|
| 118 |
+ t.Fatal("expected error, got nil")
|
|
| 119 |
+ } |
|
| 120 |
+} |
|
| 121 |
+ |
|
| 122 |
+func TestDaemonConfigurationMergeConcurrentError(t *testing.T) {
|
|
| 123 |
+ f, err := ioutil.TempFile("", "docker-config-")
|
|
| 124 |
+ if err != nil {
|
|
| 125 |
+ t.Fatal(err) |
|
| 126 |
+ } |
|
| 127 |
+ |
|
| 128 |
+ configFile := f.Name() |
|
| 129 |
+ f.Write([]byte(`{"max-concurrent-downloads": -1}`))
|
|
| 130 |
+ f.Close() |
|
| 131 |
+ |
|
| 132 |
+ _, err = MergeDaemonConfigurations(&Config{}, nil, configFile)
|
|
| 133 |
+ if err == nil {
|
|
| 134 |
+ t.Fatalf("expected no error, got error %v", err)
|
|
| 135 |
+ } |
|
| 136 |
+} |
|
| 137 |
+ |
|
| 106 | 138 |
func TestDaemonConfigurationMergeConflictsWithInnerStructs(t *testing.T) {
|
| 107 | 139 |
f, err := ioutil.TempFile("", "docker-config-")
|
| 108 | 140 |
if err != nil {
|
| ... | ... |
@@ -240,6 +272,7 @@ func TestValidateConfigurationErrors(t *testing.T) {
|
| 240 | 240 |
} |
| 241 | 241 |
|
| 242 | 242 |
func TestValidateConfiguration(t *testing.T) {
|
| 243 |
+ minusNumber := 4 |
|
| 243 | 244 |
testCases := []struct {
|
| 244 | 245 |
config *Config |
| 245 | 246 |
}{
|
| ... | ... |
@@ -264,6 +297,28 @@ func TestValidateConfiguration(t *testing.T) {
|
| 264 | 264 |
}, |
| 265 | 265 |
}, |
| 266 | 266 |
}, |
| 267 |
+ {
|
|
| 268 |
+ config: &Config{
|
|
| 269 |
+ CommonConfig: CommonConfig{
|
|
| 270 |
+ MaxConcurrentDownloads: &minusNumber, |
|
| 271 |
+ // This is weird... |
|
| 272 |
+ ValuesSet: map[string]interface{}{
|
|
| 273 |
+ "max-concurrent-downloads": -1, |
|
| 274 |
+ }, |
|
| 275 |
+ }, |
|
| 276 |
+ }, |
|
| 277 |
+ }, |
|
| 278 |
+ {
|
|
| 279 |
+ config: &Config{
|
|
| 280 |
+ CommonConfig: CommonConfig{
|
|
| 281 |
+ MaxConcurrentUploads: &minusNumber, |
|
| 282 |
+ // This is weird... |
|
| 283 |
+ ValuesSet: map[string]interface{}{
|
|
| 284 |
+ "max-concurrent-uploads": -1, |
|
| 285 |
+ }, |
|
| 286 |
+ }, |
|
| 287 |
+ }, |
|
| 288 |
+ }, |
|
| 267 | 289 |
} |
| 268 | 290 |
for _, tc := range testCases {
|
| 269 | 291 |
err := Validate(tc.config) |