runconfig: opts: parse: lowercase errors

also fix wrong function comment

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-02-18 09:26:47 +01:00
Родитель 776c5ee299
Коммит d266142230
4 изменённых файлов: 21 добавлений и 24 удалений

Просмотреть файл

@ -146,7 +146,7 @@ type Image interface {
// ImageCache abstracts an image cache store.
// (parent image, child runconfig) -> child image
type ImageCache interface {
// GetCachedImage returns a reference to a cached image whose parent equals `parent`
// GetCachedImageOnBuild returns a reference to a cached image whose parent equals `parent`
// and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
GetCachedImageOnBuild(parentID string, cfg *container.Config) (imageID string, err error)
}

Просмотреть файл

@ -2312,13 +2312,10 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) {
}
}
// test docker run expose a invalid port
func (s *DockerSuite) TestRunExposePort(c *check.C) {
out, _, err := dockerCmdWithError("run", "--expose", "80000", "busybox")
//expose a invalid port should with a error out
if err == nil || !strings.Contains(out, "Invalid range format for --expose") {
c.Fatalf("run --expose a invalid port should with error out")
}
c.Assert(err, checker.NotNil, check.Commentf("--expose with an invalid port should error out"))
c.Assert(out, checker.Contains, "invalid range format for --expose")
}
func (s *DockerSuite) TestRunUnknownCommand(c *check.C) {

Просмотреть файл

@ -191,7 +191,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
swappiness := *flSwappiness
if swappiness != -1 && (swappiness < 0 || swappiness > 100) {
return nil, nil, nil, cmd, fmt.Errorf("Invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
return nil, nil, nil, cmd, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
}
var shmSize int64
@ -257,7 +257,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
// Merge in exposed ports to the map of published ports
for _, e := range flExpose.GetAll() {
if strings.Contains(e, ":") {
return nil, nil, nil, cmd, fmt.Errorf("Invalid port format for --expose: %s", e)
return nil, nil, nil, cmd, fmt.Errorf("invalid port format for --expose: %s", e)
}
//support two formats for expose, original format <portnum>/[<proto>] or <startport-endport>/[<proto>]
proto, port := nat.SplitProtoPort(e)
@ -265,7 +265,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
//if expose a port, the start and end port are the same
start, end, err := nat.ParsePortRange(port)
if err != nil {
return nil, nil, nil, cmd, fmt.Errorf("Invalid range format for --expose: %s, error: %s", e, err)
return nil, nil, nil, cmd, fmt.Errorf("invalid range format for --expose: %s, error: %s", e, err)
}
for i := start; i <= end; i++ {
p, err := nat.NewPort(proto, strconv.FormatUint(i, 10))
@ -491,7 +491,7 @@ func ConvertKVStringsToMap(values []string) map[string]string {
func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) {
loggingOptsMap := ConvertKVStringsToMap(loggingOpts)
if loggingDriver == "none" && len(loggingOpts) > 0 {
return map[string]string{}, fmt.Errorf("Invalid logging opts for driver %s", loggingDriver)
return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver)
}
return loggingOptsMap, nil
}
@ -501,16 +501,16 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
for key, opt := range securityOpts {
con := strings.SplitN(opt, ":", 2)
if len(con) == 1 {
return securityOpts, fmt.Errorf("Invalid --security-opt: %q", opt)
return securityOpts, fmt.Errorf("invalid --security-opt: %q", opt)
}
if con[0] == "seccomp" && con[1] != "unconfined" {
f, err := ioutil.ReadFile(con[1])
if err != nil {
return securityOpts, fmt.Errorf("Opening seccomp profile (%s) failed: %v", con[1], err)
return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
}
b := bytes.NewBuffer(nil)
if err := json.Compact(b, f); err != nil {
return securityOpts, fmt.Errorf("Compacting json for seccomp profile (%s) failed: %v", con[1], err)
return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
}
securityOpts[key] = fmt.Sprintf("seccomp:%s", b.Bytes())
}
@ -579,7 +579,7 @@ func ParseDevice(device string) (container.DeviceMapping, error) {
case 1:
src = arr[0]
default:
return container.DeviceMapping{}, fmt.Errorf("Invalid device specification: %s", device)
return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
}
if dst == "" {

Просмотреть файл

@ -401,14 +401,14 @@ func TestParseHostname(t *testing.T) {
func TestParseWithExpose(t *testing.T) {
invalids := map[string]string{
":": "Invalid port format for --expose: :",
"8080:9090": "Invalid port format for --expose: 8080:9090",
"/tcp": "Invalid range format for --expose: /tcp, error: Empty string specified for ports.",
"/udp": "Invalid range format for --expose: /udp, error: Empty string specified for ports.",
"NaN/tcp": `Invalid range format for --expose: NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"NaN-NaN/tcp": `Invalid range format for --expose: NaN-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"8080-NaN/tcp": `Invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"1234567890-8080/tcp": `Invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
":": "invalid port format for --expose: :",
"8080:9090": "invalid port format for --expose: 8080:9090",
"/tcp": "invalid range format for --expose: /tcp, error: Empty string specified for ports.",
"/udp": "invalid range format for --expose: /udp, error: Empty string specified for ports.",
"NaN/tcp": `invalid range format for --expose: NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"NaN-NaN/tcp": `invalid range format for --expose: NaN-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"8080-NaN/tcp": `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
"1234567890-8080/tcp": `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
}
valids := map[string][]nat.Port{
"8080/tcp": {"8080/tcp"},
@ -578,8 +578,8 @@ func TestParseRestartPolicy(t *testing.T) {
func TestParseLoggingOpts(t *testing.T) {
// logging opts ko
if _, _, _, _, err := parseRun([]string{"--log-driver=none", "--log-opt=anything", "img", "cmd"}); err == nil || err.Error() != "Invalid logging opts for driver none" {
t.Fatalf("Expected an error with message 'Invalid logging opts for driver none', got %v", err)
if _, _, _, _, err := parseRun([]string{"--log-driver=none", "--log-opt=anything", "img", "cmd"}); err == nil || err.Error() != "invalid logging opts for driver none" {
t.Fatalf("Expected an error with message 'invalid logging opts for driver none', got %v", err)
}
// logging opts ok
_, hostconfig, _, _, err := parseRun([]string{"--log-driver=syslog", "--log-opt=something", "img", "cmd"})