1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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
parent 776c5ee299
commit d266142230
4 changed files with 21 additions and 24 deletions

View file

@ -146,7 +146,7 @@ type Image interface {
// ImageCache abstracts an image cache store. // ImageCache abstracts an image cache store.
// (parent image, child runconfig) -> child image // (parent image, child runconfig) -> child image
type ImageCache interface { 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. // 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) GetCachedImageOnBuild(parentID string, cfg *container.Config) (imageID string, err error)
} }

View file

@ -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) { func (s *DockerSuite) TestRunExposePort(c *check.C) {
out, _, err := dockerCmdWithError("run", "--expose", "80000", "busybox") out, _, err := dockerCmdWithError("run", "--expose", "80000", "busybox")
//expose a invalid port should with a error out c.Assert(err, checker.NotNil, check.Commentf("--expose with an invalid port should error out"))
if err == nil || !strings.Contains(out, "Invalid range format for --expose") { c.Assert(out, checker.Contains, "invalid range format for --expose")
c.Fatalf("run --expose a invalid port should with error out")
}
} }
func (s *DockerSuite) TestRunUnknownCommand(c *check.C) { func (s *DockerSuite) TestRunUnknownCommand(c *check.C) {

View file

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

View file

@ -401,14 +401,14 @@ func TestParseHostname(t *testing.T) {
func TestParseWithExpose(t *testing.T) { func TestParseWithExpose(t *testing.T) {
invalids := map[string]string{ invalids := map[string]string{
":": "Invalid port format for --expose: :", ":": "invalid port format for --expose: :",
"8080:9090": "Invalid port format for --expose: 8080:9090", "8080:9090": "invalid port format for --expose: 8080:9090",
"/tcp": "Invalid range format for --expose: /tcp, error: Empty string specified for ports.", "/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.", "/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/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`, "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`, "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`, "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{ valids := map[string][]nat.Port{
"8080/tcp": {"8080/tcp"}, "8080/tcp": {"8080/tcp"},
@ -578,8 +578,8 @@ func TestParseRestartPolicy(t *testing.T) {
func TestParseLoggingOpts(t *testing.T) { func TestParseLoggingOpts(t *testing.T) {
// logging opts ko // 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" { 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) t.Fatalf("Expected an error with message 'invalid logging opts for driver none', got %v", err)
} }
// logging opts ok // logging opts ok
_, hostconfig, _, _, err := parseRun([]string{"--log-driver=syslog", "--log-opt=something", "img", "cmd"}) _, hostconfig, _, _, err := parseRun([]string{"--log-driver=syslog", "--log-opt=something", "img", "cmd"})