-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Fix docker run --expose with an invalid port does not error out #10856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Shoud I add test for this? |
Nice simplification! A test to validate error on invalid port would be great. |
We ❤️ tests :D |
update, add a test for expose a invalid port @jfrazelle |
if err != nil && !strings.Contains(out, "Invalid range format for --expose") { | ||
t.Fatalf("failed to run container, output: %q", out) | ||
} | ||
if !strings.Contains(out, "Invalid range format for --expose") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failing test would never reach this point since you are testing for this above @ 2726.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
052e3bc
to
234fd5e
Compare
@cpuguy83 @jfrazelle the test has updated |
// test docker run expose a invalid port | ||
func TestRunExposePort(t *testing.T) { | ||
runCmd := exec.Command(dockerBinary, "run", "--expose", "80000", "busybox") | ||
_, _, err := runCommandWithOutput(runCmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it's often extremely helpful to get the actual output text here as part of the test's error message, and then we can do a !strings.Contains(<some error string here>)
to make sure we go the error we thought we should.
LGTM after nits with the test. |
thanks for the test! looks good ping me after the changes for the merge :D |
Signed-off-by: Lei Jitang <leijitang@huawei.com>
234fd5e
to
34b7c10
Compare
update the test, ping @jfrazelle |
LGTM |
thanks @coolljt0725 |
Fix docker run --expose with an invalid port does not error out
Signed-off-by: Lei Jitang leijitang@huawei.com
Fixes #10836
when
docker run --expose
with an invalid port, there is no error out.This patch fix this and have some refactor to previous code to make the code
more simplified. Since function
parsers.ParsePortRange
will dostrings.Contains(e, "-")
and if the port is not a range but a specified one, the returnstart port
andend port
are the same. So there is no need to doif strings.Contains(e, "-")
in
parse.go