Browse code

runconfig: opts: parse: lowercase errors

also fix wrong function comment

Signed-off-by: Antonio Murdaca <runcom@redhat.com>

Antonio Murdaca authored on 2016/02/18 17:26:47
Showing 4 changed files
... ...
@@ -146,7 +146,7 @@ type Image interface {
146 146
 // ImageCache abstracts an image cache store.
147 147
 // (parent image, child runconfig) -> child image
148 148
 type ImageCache interface {
149
-	// GetCachedImage returns a reference to a cached image whose parent equals `parent`
149
+	// GetCachedImageOnBuild returns a reference to a cached image whose parent equals `parent`
150 150
 	// and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
151 151
 	GetCachedImageOnBuild(parentID string, cfg *container.Config) (imageID string, err error)
152 152
 }
... ...
@@ -2312,13 +2312,10 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) {
2312 2312
 	}
2313 2313
 }
2314 2314
 
2315
-// test docker run expose a invalid port
2316 2315
 func (s *DockerSuite) TestRunExposePort(c *check.C) {
2317 2316
 	out, _, err := dockerCmdWithError("run", "--expose", "80000", "busybox")
2318
-	//expose a invalid port should with a error out
2319
-	if err == nil || !strings.Contains(out, "Invalid range format for --expose") {
2320
-		c.Fatalf("run --expose a invalid port should with error out")
2321
-	}
2317
+	c.Assert(err, checker.NotNil, check.Commentf("--expose with an invalid port should error out"))
2318
+	c.Assert(out, checker.Contains, "invalid range format for --expose")
2322 2319
 }
2323 2320
 
2324 2321
 func (s *DockerSuite) TestRunUnknownCommand(c *check.C) {
... ...
@@ -191,7 +191,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
191 191
 
192 192
 	swappiness := *flSwappiness
193 193
 	if swappiness != -1 && (swappiness < 0 || swappiness > 100) {
194
-		return nil, nil, nil, cmd, fmt.Errorf("Invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
194
+		return nil, nil, nil, cmd, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
195 195
 	}
196 196
 
197 197
 	var shmSize int64
... ...
@@ -257,7 +257,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
257 257
 	// Merge in exposed ports to the map of published ports
258 258
 	for _, e := range flExpose.GetAll() {
259 259
 		if strings.Contains(e, ":") {
260
-			return nil, nil, nil, cmd, fmt.Errorf("Invalid port format for --expose: %s", e)
260
+			return nil, nil, nil, cmd, fmt.Errorf("invalid port format for --expose: %s", e)
261 261
 		}
262 262
 		//support two formats for expose, original format <portnum>/[<proto>] or <startport-endport>/[<proto>]
263 263
 		proto, port := nat.SplitProtoPort(e)
... ...
@@ -265,7 +265,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
265 265
 		//if expose a port, the start and end port are the same
266 266
 		start, end, err := nat.ParsePortRange(port)
267 267
 		if err != nil {
268
-			return nil, nil, nil, cmd, fmt.Errorf("Invalid range format for --expose: %s, error: %s", e, err)
268
+			return nil, nil, nil, cmd, fmt.Errorf("invalid range format for --expose: %s, error: %s", e, err)
269 269
 		}
270 270
 		for i := start; i <= end; i++ {
271 271
 			p, err := nat.NewPort(proto, strconv.FormatUint(i, 10))
... ...
@@ -491,7 +491,7 @@ func ConvertKVStringsToMap(values []string) map[string]string {
491 491
 func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) {
492 492
 	loggingOptsMap := ConvertKVStringsToMap(loggingOpts)
493 493
 	if loggingDriver == "none" && len(loggingOpts) > 0 {
494
-		return map[string]string{}, fmt.Errorf("Invalid logging opts for driver %s", loggingDriver)
494
+		return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver)
495 495
 	}
496 496
 	return loggingOptsMap, nil
497 497
 }
... ...
@@ -501,16 +501,16 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
501 501
 	for key, opt := range securityOpts {
502 502
 		con := strings.SplitN(opt, ":", 2)
503 503
 		if len(con) == 1 {
504
-			return securityOpts, fmt.Errorf("Invalid --security-opt: %q", opt)
504
+			return securityOpts, fmt.Errorf("invalid --security-opt: %q", opt)
505 505
 		}
506 506
 		if con[0] == "seccomp" && con[1] != "unconfined" {
507 507
 			f, err := ioutil.ReadFile(con[1])
508 508
 			if err != nil {
509
-				return securityOpts, fmt.Errorf("Opening seccomp profile (%s) failed: %v", con[1], err)
509
+				return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
510 510
 			}
511 511
 			b := bytes.NewBuffer(nil)
512 512
 			if err := json.Compact(b, f); err != nil {
513
-				return securityOpts, fmt.Errorf("Compacting json for seccomp profile (%s) failed: %v", con[1], err)
513
+				return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
514 514
 			}
515 515
 			securityOpts[key] = fmt.Sprintf("seccomp:%s", b.Bytes())
516 516
 		}
... ...
@@ -579,7 +579,7 @@ func ParseDevice(device string) (container.DeviceMapping, error) {
579 579
 	case 1:
580 580
 		src = arr[0]
581 581
 	default:
582
-		return container.DeviceMapping{}, fmt.Errorf("Invalid device specification: %s", device)
582
+		return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
583 583
 	}
584 584
 
585 585
 	if dst == "" {
... ...
@@ -401,14 +401,14 @@ func TestParseHostname(t *testing.T) {
401 401
 
402 402
 func TestParseWithExpose(t *testing.T) {
403 403
 	invalids := map[string]string{
404
-		":":                   "Invalid port format for --expose: :",
405
-		"8080:9090":           "Invalid port format for --expose: 8080:9090",
406
-		"/tcp":                "Invalid range format for --expose: /tcp, error: Empty string specified for ports.",
407
-		"/udp":                "Invalid range format for --expose: /udp, error: Empty string specified for ports.",
408
-		"NaN/tcp":             `Invalid range format for --expose: NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
409
-		"NaN-NaN/tcp":         `Invalid range format for --expose: NaN-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
410
-		"8080-NaN/tcp":        `Invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
411
-		"1234567890-8080/tcp": `Invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
404
+		":":                   "invalid port format for --expose: :",
405
+		"8080:9090":           "invalid port format for --expose: 8080:9090",
406
+		"/tcp":                "invalid range format for --expose: /tcp, error: Empty string specified for ports.",
407
+		"/udp":                "invalid range format for --expose: /udp, error: Empty string specified for ports.",
408
+		"NaN/tcp":             `invalid range format for --expose: NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
409
+		"NaN-NaN/tcp":         `invalid range format for --expose: NaN-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
410
+		"8080-NaN/tcp":        `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
411
+		"1234567890-8080/tcp": `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
412 412
 	}
413 413
 	valids := map[string][]nat.Port{
414 414
 		"8080/tcp":      {"8080/tcp"},
... ...
@@ -578,8 +578,8 @@ func TestParseRestartPolicy(t *testing.T) {
578 578
 
579 579
 func TestParseLoggingOpts(t *testing.T) {
580 580
 	// logging opts ko
581
-	if _, _, _, _, err := parseRun([]string{"--log-driver=none", "--log-opt=anything", "img", "cmd"}); err == nil || err.Error() != "Invalid logging opts for driver none" {
582
-		t.Fatalf("Expected an error with message 'Invalid logging opts for driver none', got %v", err)
581
+	if _, _, _, _, err := parseRun([]string{"--log-driver=none", "--log-opt=anything", "img", "cmd"}); err == nil || err.Error() != "invalid logging opts for driver none" {
582
+		t.Fatalf("Expected an error with message 'invalid logging opts for driver none', got %v", err)
583 583
 	}
584 584
 	// logging opts ok
585 585
 	_, hostconfig, _, _, err := parseRun([]string{"--log-driver=syslog", "--log-opt=something", "img", "cmd"})